fix: crash while updating link text on the last node (#3871)

This commit is contained in:
M. Palanikannan 2024-03-04 20:33:16 +05:30 committed by GitHub
parent 6eb7014ea4
commit d99529b109
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,9 +40,11 @@ export const LinkEditView = ({
const [positionRef, setPositionRef] = useState({ from: from, to: to }); const [positionRef, setPositionRef] = useState({ from: from, to: to });
const [localUrl, setLocalUrl] = useState(viewProps.url); const [localUrl, setLocalUrl] = useState(viewProps.url);
const linkRemoved = useRef<Boolean>(); const linkRemoved = useRef<boolean>();
const getText = (from: number, to: number) => { const getText = (from: number, to: number) => {
if (to >= editor.state.doc.content.size) return "";
const text = editor.state.doc.textBetween(from, to, "\n"); const text = editor.state.doc.textBetween(from, to, "\n");
return text; return text;
}; };
@ -72,10 +74,12 @@ export const LinkEditView = ({
const url = isValidUrl(localUrl) ? localUrl : viewProps.url; const url = isValidUrl(localUrl) ? localUrl : viewProps.url;
if (to >= editor.state.doc.content.size) return;
editor.view.dispatch(editor.state.tr.removeMark(from, to, editor.schema.marks.link)); editor.view.dispatch(editor.state.tr.removeMark(from, to, editor.schema.marks.link));
editor.view.dispatch(editor.state.tr.addMark(from, to, editor.schema.marks.link.create({ href: url }))); editor.view.dispatch(editor.state.tr.addMark(from, to, editor.schema.marks.link.create({ href: url })));
}, },
[localUrl] [localUrl, editor, from, to, viewProps.url]
); );
const handleUpdateText = (text: string) => { const handleUpdateText = (text: string) => {