mirror of https://github.com/fantasticit/think.git
tiptap: fix edit link when only one letter
parent
3f19e0715a
commit
0eff8aa9ab
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue