From cf97ed94a3cc2f1da459cf0329a3538410efe889 Mon Sep 17 00:00:00 2001 From: PathGao <42336971+PathGao@users.noreply.github.com> Date: Thu, 16 Jul 2026 16:20:15 +0900 Subject: [PATCH] fix: pasting a URL over a selected URL replaces it instead of nesting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Paste-as-link wraps the selection unconditionally: [selected](pasted). When the selection is itself a URL — the natural gesture for swapping a link target, including inside image syntax — this produces broken nesting like ![]([old](new). Follow the editor convention (VS Code does the same) and plain-replace when the selected text is already a URL. Co-Authored-By: Claude Fable 5 --- src/lib/components/Editor.svelte | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/components/Editor.svelte b/src/lib/components/Editor.svelte index b384ab5..32f635c 100644 --- a/src/lib/components/Editor.svelte +++ b/src/lib/components/Editor.svelte @@ -943,6 +943,17 @@ if (hasSelection) { const edits = selections.map((selection) => { const selectedText = model.getValueInRange(selection); + // Pasting a URL over a URL replaces it. Wrapping would + // nest the old URL as the link text — and inside + // existing link syntax like ![](url) it produces + // broken nesting: ![]([old](new)). + if (urlRegex.test(selectedText.trim())) { + return { + range: selection, + text, + forceMoveMarkers: true, + }; + } const linkUrl = text.toLowerCase().startsWith("www.") ? `http://${text}` : text;