mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-09-21 02:17:29 +02:00
fix: stop wiki links extending after autocomplete
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { TextSelection, type EditorState, type Transaction } from '@tiptap/pm/state';
|
||||
|
||||
export type WikiLinkAttributes = {
|
||||
title: string;
|
||||
path: string;
|
||||
aliased: boolean;
|
||||
};
|
||||
|
||||
export function replaceWithWikiLink(
|
||||
state: EditorState,
|
||||
from: number,
|
||||
to: number,
|
||||
text: string,
|
||||
attrs: WikiLinkAttributes
|
||||
): Transaction {
|
||||
const wikiLinkMark = state.schema.marks.wikiLink.create(attrs);
|
||||
const textNode = state.schema.text(text, [wikiLinkMark]);
|
||||
const transaction = state.tr.replaceWith(from, to, textNode);
|
||||
transaction.setSelection(TextSelection.create(transaction.doc, from + text.length));
|
||||
transaction.setStoredMarks([]);
|
||||
return transaction;
|
||||
}
|
||||
Reference in New Issue
Block a user