From 3709bef53bdcecd7abee91af5519618cda2b1654 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 13 Oct 2025 19:49:44 +0200 Subject: [PATCH] [v12.0/forgejo] fix: avoid jumping to begin of page on edit comment action (#9645) (#9671) **Backport: forgejo/forgejo#9645** When you edit a comment and the comment already has a markdown editor, then the code will click on the 'Write' tab, in case you canceled editting the comment when you were at the 'Preview' tab. In forgejo/forgejo#2681 I added `href="#"` to the tab items, this causes that when the 'Write' tab is being clicked by the code the page is jumped the beginning of the page. Instead of being clever and trying to make this item interactive via another way or via javascript avoid this jumping, we do better and make this element a button. This item is not a link, it's a button that will perform a action. This entirely avoids the issue of jumping and it's still interactive. Resolves forgejo/forgejo#9542 ---- Conflict resolution: trivial (cherry picked from commit d0a6f93f9ee17471e0f848d31e71c60285ff127d) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9671 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Gusted Co-committed-by: Gusted --- templates/shared/combomarkdowneditor.tmpl | 4 ++-- tests/e2e/issue-comment.test.e2e.ts | 6 +++--- tests/e2e/markdown-editor.test.e2e.ts | 4 ++-- web_src/js/features/repo-legacy.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/shared/combomarkdowneditor.tmpl b/templates/shared/combomarkdowneditor.tmpl index febca5ec7f..21462e8051 100644 --- a/templates/shared/combomarkdowneditor.tmpl +++ b/templates/shared/combomarkdowneditor.tmpl @@ -18,8 +18,8 @@ Template Attributes: {{if .MarkdownPreviewUrl}}
- {{ctx.Locale.Tr "write"}} - {{ctx.Locale.Tr "preview"}} + +
{{end}} diff --git a/tests/e2e/issue-comment.test.e2e.ts b/tests/e2e/issue-comment.test.e2e.ts index 2017e4563e..d17c544fd0 100644 --- a/tests/e2e/issue-comment.test.e2e.ts +++ b/tests/e2e/issue-comment.test.e2e.ts @@ -61,7 +61,7 @@ test('Always focus edit tab first on edit', async ({page}) => { // Switch to preview tab and save await page.click('#issue-1 .comment-container .context-menu'); await page.click('#issue-1 .comment-container .menu>.edit-content'); - await page.locator('#issue-1 .comment-container a[data-tab-for=markdown-previewer]').click(); + await page.locator('#issue-1 .comment-container [data-tab-for=markdown-previewer]').click(); await page.click('#issue-1 .comment-container .save'); await page.waitForLoadState(); @@ -69,8 +69,8 @@ test('Always focus edit tab first on edit', async ({page}) => { // Edit again and assert that edit tab should be active (and not preview tab) await page.click('#issue-1 .comment-container .context-menu'); await page.click('#issue-1 .comment-container .menu>.edit-content'); - const editTab = page.locator('#issue-1 .comment-container a[data-tab-for=markdown-writer]'); - const previewTab = page.locator('#issue-1 .comment-container a[data-tab-for=markdown-previewer]'); + const editTab = page.locator('#issue-1 .comment-container [data-tab-for=markdown-writer]'); + const previewTab = page.locator('#issue-1 .comment-container [data-tab-for=markdown-previewer]'); await expect(editTab).toHaveClass(/active/); await expect(previewTab).not.toHaveClass(/active/); diff --git a/tests/e2e/markdown-editor.test.e2e.ts b/tests/e2e/markdown-editor.test.e2e.ts index 7983907343..82a7a57e30 100644 --- a/tests/e2e/markdown-editor.test.e2e.ts +++ b/tests/e2e/markdown-editor.test.e2e.ts @@ -436,7 +436,7 @@ test('Combo Markdown: preview mode switch', async ({page}) => { await textarea.fill('**Content** :100: _100_'); // Switch to preview mode - await page.locator('a[data-tab-for="markdown-previewer"]').click(); + await page.locator('[data-tab-for="markdown-previewer"]').click(); // Verify that the related UI elements were switched correctly await expect(toolbarItem).toBeHidden(); @@ -448,7 +448,7 @@ test('Combo Markdown: preview mode switch', async ({page}) => { await expect(page.locator('[data-tab-panel="markdown-previewer"] .emoji[data-alias="100"]')).toBeVisible(); // Switch back to edit mode - await page.locator('a[data-tab-for="markdown-writer"]').click(); + await page.locator('[data-tab-for="markdown-writer"]').click(); // Verify that the related UI elements were switched back correctly await expect(toolbarItem).toBeVisible(); diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 66ee945d02..581e0b3899 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -379,7 +379,7 @@ async function onEditContent(event) { editContentZone.querySelector('button[data-button-name="cancel-edit"]').addEventListener('click', cancelAndReset); editContentZone.querySelector('button[data-button-name="save-edit"]').addEventListener('click', saveAndRefresh); } else { - const tabEditor = editContentZone.querySelector('.combo-markdown-editor').querySelector('.switch > a[data-tab-for=markdown-writer]'); + const tabEditor = editContentZone.querySelector('.combo-markdown-editor').querySelector('.switch > [data-tab-for=markdown-writer]'); tabEditor?.click(); }