mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
Fix wiki-link mark bleeding past ]] closure
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user