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 curTo = state.selection.from;
closeWikiLinkMenu();
// Delete [[ text + query + the trailing ]
editor?.chain().focus().deleteRange({ from: menuFrom, to: curTo }).run();
tick().then(() => {
editor?.chain().focus().insertContent({
type: 'text',
text: display,
marks: [{ type: 'wikiLink', attrs: { title: noteRef, path: '', aliased: display !== noteRef } }],
}).run();
if (!editor) return;
// Use a single ProseMirror transaction to replace [[query] with the
// wiki-link and clear stored marks atomically, preventing the inclusive
// mark from bleeding into subsequent text. Do NOT call deleteRange first
// — 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 {