From ebd32d626f6fca8ac768c2d78cab2d58fada6a77 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sun, 1 Sep 2024 17:15:29 +0200 Subject: [PATCH] Improve textarea paste (part of gitea#31948) When pasting a URL over another URL, replace the URL instead of creating a useless `[url](url)`. (Partially picked from commit 55502265716f000a2c61c98fa093244e1310d97f) Signed-off-by: Gergely Nagy --- web_src/js/features/comp/Paste.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/features/comp/Paste.js b/web_src/js/features/comp/Paste.js index aab6997ad5..7e4ecbbeda 100644 --- a/web_src/js/features/comp/Paste.js +++ b/web_src/js/features/comp/Paste.js @@ -116,7 +116,7 @@ function handleClipboardText(textarea, text, e) { if (_shiftDown) return; const selectedText = value.substring(selectionStart, selectionEnd); const trimmedText = text.trim(); - if (selectedText && isUrl(trimmedText)) { + if (selectedText && isUrl(trimmedText) && !isUrl(selectedText)) { e.stopPropagation(); e.preventDefault(); replaceTextareaSelection(textarea, `[${selectedText}](${trimmedText})`);