tiptap: fix edit link when only one letter

This commit is contained in:
fantasticit 2022-06-16 16:31:30 +08:00
parent 3f19e0715a
commit 0eff8aa9ab
1 changed files with 19 additions and 9 deletions

View File

@ -39,10 +39,13 @@ export const LinkBubbleMenu = ({ editor }) => {
if (!isInLink) return;
const { $head } = editor.state.selection;
const { $head, from, to } = editor.state.selection;
const marks = $head.marks();
if (!marks.length) return;
let start;
let end;
if (marks.length) {
const mark = marks[0];
const node = $head.node($head.depth);
const startPosOfThisLine = $head.pos - (($head.nodeBefore && $head.nodeBefore.nodeSize) || 0);
@ -50,7 +53,14 @@ export const LinkBubbleMenu = ({ editor }) => {
? startPosOfThisLine + $head.nodeAfter.nodeSize
: $head.pos - $head.parentOffset + node.content.size;
const { start, end } = findMarkPosition(state, mark, startPosOfThisLine, endPosOfThisLine);
const { start: startPos, end: endPos } = findMarkPosition(state, mark, startPosOfThisLine, endPosOfThisLine);
start = startPos;
end = endPos;
} else {
start = from;
end = to;
}
const text = state.doc.textBetween(start, end);
setText(text);
setFrom(start);