From 7b494a4a89b84edf8460ea18d2a3020920fd13ae Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Fri, 1 May 2026 03:08:15 -0400 Subject: [PATCH] fix: skip doc link auto-convert while cursor is inside the brackets The appendTransaction plugin was converting [[s]] immediately on the first keystroke inside [[]]. Now it checks whether the cursor sits between [[ and ]] and skips the match if so, letting the user finish typing before the conversion fires. Co-authored-by: Orca --- .../src/components/editor/rich-markdown-doc-link.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/components/editor/rich-markdown-doc-link.ts b/src/renderer/src/components/editor/rich-markdown-doc-link.ts index 4d4df3ca7ec..474ca791d15 100644 --- a/src/renderer/src/components/editor/rich-markdown-doc-link.ts +++ b/src/renderer/src/components/editor/rich-markdown-doc-link.ts @@ -73,6 +73,7 @@ export const MarkdownDocLink = Node.create({ key: docLinkAutoConvertKey, appendTransaction(_transactions, _oldState, newState) { const { tr } = newState + const cursor = newState.selection.from let modified = false newState.doc.descendants((node, pos) => { @@ -90,11 +91,15 @@ export const MarkdownDocLink = Node.create({ const from = pos + match.index const to = from + match[0].length - const docLinkNode = nodeType.create({ target }) - // Why: earlier replacements shift positions. Map through the - // transaction's current mapping so subsequent matches land at - // the correct offset. + // Why: skip matches where the cursor sits between [[ and ]]. + // The user is still typing the target — converting now would + // swallow their in-progress text into an atomic node. + if (cursor > from && cursor < to) { + continue + } + + const docLinkNode = nodeType.create({ target }) tr.replaceWith(tr.mapping.map(from), tr.mapping.map(to), docLinkNode) modified = true }