From f8099ce9e40912dd40e254a391574907438b3038 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 16 May 2025 18:43:32 +0000 Subject: [PATCH] fix: quote reply in Chromium (#7883) - Chromium would unselect the text if some text is written in another element, so temporarily store the range and restore after this writing has happened. - Resolves forgejo/forgejo#7841 - No E2E test, there is already a test case that perfectly matches the reproduce steps of this bug, however Chromium does not produce consistent behavior on this case. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7883 Reviewed-by: Otto Co-authored-by: Gusted Co-committed-by: Gusted --- web_src/js/features/repo-legacy.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 4c2ff50574..25ed181616 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -685,7 +685,12 @@ function initRepoIssueCommentEdit() { // If the selection is in the comment body, then insert the quote. if (quote.closest(`#${event.target.getAttribute('data-target')}`)) { + // Chromium quirk: Temporarily store the range so it doesn't get lost, caused by appending text in another element. + const currentRange = quote.range; + editorTextArea.value += `@${event.target.getAttribute('data-author')} wrote in ${toAbsoluteUrl(event.target.getAttribute('data-reference-url'))}:`; + + quote.range = currentRange; quote.insert(editorTextArea); } });