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,18 +39,28 @@ 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;
const mark = marks[0];
const node = $head.node($head.depth);
const startPosOfThisLine = $head.pos - (($head.nodeBefore && $head.nodeBefore.nodeSize) || 0);
const endPosOfThisLine = $head.nodeAfter
? startPosOfThisLine + $head.nodeAfter.nodeSize
: $head.pos - $head.parentOffset + node.content.size;
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);
const endPosOfThisLine = $head.nodeAfter
? startPosOfThisLine + $head.nodeAfter.nodeSize
: $head.pos - $head.parentOffset + node.content.size;
const { start: startPos, end: endPos } = findMarkPosition(state, mark, startPosOfThisLine, endPosOfThisLine);
start = startPos;
end = endPos;
} else {
start = from;
end = to;
}
const { start, end } = findMarkPosition(state, mark, startPosOfThisLine, endPosOfThisLine);
const text = state.doc.textBetween(start, end);
setText(text);
setFrom(start);