Fix wiki-link mark bleeding past ]] closure

This commit is contained in:
Yuri Karamian
2026-06-16 19:27:03 +02:00
parent 6fcf7bdb5e
commit 1164a6bd86
+21 -12
View File
@@ -2013,19 +2013,28 @@
wikiLinkDisambigDisplay = display; wikiLinkDisambigDisplay = display;
wikiLinkSelectedIndex = 0; wikiLinkSelectedIndex = 0;
} else { } else {
// Insert as unresolved wiki-link (no path) // Insert as unresolved wiki-link (no path)
const menuFrom = wikiLinkMenu.from; const menuFrom = wikiLinkMenu.from;
const curTo = state.selection.from; const curTo = state.selection.from;
closeWikiLinkMenu(); closeWikiLinkMenu();
// Delete [[ text + query + the trailing ] tick().then(() => {
editor?.chain().focus().deleteRange({ from: menuFrom, to: curTo }).run(); if (!editor) return;
tick().then(() => { // Use a single ProseMirror transaction to replace [[query] with the
editor?.chain().focus().insertContent({ // wiki-link and clear stored marks atomically, preventing the inclusive
type: 'text', // mark from bleeding into subsequent text. Do NOT call deleteRange first
text: display, // — that would shift positions and make menuFrom/curTo invalid here.
marks: [{ type: 'wikiLink', attrs: { title: noteRef, path: '', aliased: display !== noteRef } }], const { tr, schema } = editor.view.state;
}).run(); const wikiLinkMark = schema.marks.wikiLink.create({
title: noteRef,
path: '',
aliased: display !== noteRef,
}); });
const textNode = schema.text(display, [wikiLinkMark]);
tr.replaceWith(menuFrom, curTo, textNode);
tr.setSelection(TextSelection.create(tr.doc, menuFrom + display.length));
tr.setStoredMarks([]);
editor.view.dispatch(tr);
});
} }
} else { } else {
closeWikiLinkMenu(); closeWikiLinkMenu();