Skip to content

Commit

Permalink
fix: crash while updating link text on the last node (#3871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 authored Mar 4, 2024
1 parent 6eb7014 commit d99529b
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export const LinkEditView = ({
const [positionRef, setPositionRef] = useState({ from: from, to: to });
const [localUrl, setLocalUrl] = useState(viewProps.url);

const linkRemoved = useRef<Boolean>();
const linkRemoved = useRef<boolean>();

const getText = (from: number, to: number) => {
if (to >= editor.state.doc.content.size) return "";

const text = editor.state.doc.textBetween(from, to, "\n");
return text;
};
Expand Down Expand Up @@ -72,10 +74,12 @@ export const LinkEditView = ({

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.addMark(from, to, editor.schema.marks.link.create({ href: url })));
},
[localUrl]
[localUrl, editor, from, to, viewProps.url]
);

const handleUpdateText = (text: string) => {
Expand Down

0 comments on commit d99529b

Please sign in to comment.