From b1b99d5c70317373b9e6393de6f97e05a2cec499 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 13 Oct 2025 23:05:03 +0200 Subject: [PATCH] [v13.0/forgejo] fix: avoid jumping to begin of page on edit comment action (#9645) (#9674) **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/9674 Reviewed-by: Otto Co-authored-by: Gusted Co-committed-by: Gusted --- templates/shared/combomarkdowneditor.tmpl | 5 ++--- 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(+), 9 deletions(-) diff --git a/templates/shared/combomarkdowneditor.tmpl b/templates/shared/combomarkdowneditor.tmpl index ce1be8b48e..15cf45f2cf 100644 --- a/templates/shared/combomarkdowneditor.tmpl +++ b/templates/shared/combomarkdowneditor.tmpl @@ -18,9 +18,8 @@ Template Attributes: {{if .MarkdownPreviewUrl}}
+ +
{{end}}
diff --git a/tests/e2e/issue-comment.test.e2e.ts b/tests/e2e/issue-comment.test.e2e.ts index bc2bc3d691..d71b3a2d72 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 c2d4057bc9..07d8620a56 100644 --- a/tests/e2e/markdown-editor.test.e2e.ts +++ b/tests/e2e/markdown-editor.test.e2e.ts @@ -438,7 +438,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(); @@ -450,7 +450,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(); }