From 34e1100ae22ef4fe70bace46ffa954aba85a0620 Mon Sep 17 00:00:00 2001 From: Beowulf Date: Fri, 17 Jan 2025 20:14:28 +0000 Subject: [PATCH] fix(ui): reset content of text field for comments when cancelling (#6595) Currently, the content of the text field is not reset when you cancel editing. This change resets the content of the text field when editing is canceled. If this is not done and you click on cancel and then on edit again, you can no longer return to the initial content without completely reloading the page. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6595 Reviewed-by: Otto Reviewed-by: Gusted Co-authored-by: Beowulf Co-committed-by: Beowulf --- tests/e2e/issue-comment.test.e2e.ts | 21 +++++++++++++++++++++ web_src/js/features/repo-legacy.js | 1 + 2 files changed, 22 insertions(+) diff --git a/tests/e2e/issue-comment.test.e2e.ts b/tests/e2e/issue-comment.test.e2e.ts index 933e65fa32..1c19f98c48 100644 --- a/tests/e2e/issue-comment.test.e2e.ts +++ b/tests/e2e/issue-comment.test.e2e.ts @@ -77,6 +77,27 @@ test('Always focus edit tab first on edit', async ({page}) => { await save_visual(page); }); +test('Reset content of comment edit field on cancel', async ({page}) => { + const response = await page.goto('/user2/repo1/issues/1'); + expect(response?.status()).toBe(200); + + const editorTextarea = page.locator('[id="_combo_markdown_editor_1"]'); + + // Change the content of the edit field + await page.click('#issue-1 .comment-container .context-menu'); + await page.click('#issue-1 .comment-container .menu>.edit-content'); + await expect(editorTextarea).toHaveValue('content for the first issue'); + await editorTextarea.fill('some random string'); + await expect(editorTextarea).toHaveValue('some random string'); + await page.click('#issue-1 .comment-container .edit .cancel'); + + // Edit again and assert that the edit field should be reset to the initial content + await page.click('#issue-1 .comment-container .context-menu'); + await page.click('#issue-1 .comment-container .menu>.edit-content'); + await expect(editorTextarea).toHaveValue('content for the first issue'); + await save_visual(page); +}); + test('Quote reply', async ({page}, workerInfo) => { test.skip(workerInfo.project.name !== 'firefox', 'Uses Firefox specific selection quirks'); const response = await page.goto('/user2/repo1/issues/1'); diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 04b6e93b39..c74ba1efbe 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -405,6 +405,7 @@ async function onEditContent(event) { e.preventDefault(); showElem(renderContent); hideElem(editContentZone); + comboMarkdownEditor.value(rawContent.textContent); comboMarkdownEditor.attachedDropzoneInst?.emit('reload'); };