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
+16 -7
View File
@@ -2017,14 +2017,23 @@
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 ]
editor?.chain().focus().deleteRange({ from: menuFrom, to: curTo }).run();
tick().then(() => { tick().then(() => {
editor?.chain().focus().insertContent({ if (!editor) return;
type: 'text', // Use a single ProseMirror transaction to replace [[query] with the
text: display, // wiki-link and clear stored marks atomically, preventing the inclusive
marks: [{ type: 'wikiLink', attrs: { title: noteRef, path: '', aliased: display !== noteRef } }], // mark from bleeding into subsequent text. Do NOT call deleteRange first
}).run(); // — that would shift positions and make menuFrom/curTo invalid here.
const { tr, schema } = editor.view.state;
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 {