Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

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

M. Palanikannand99529b109fe
diff --git a/packages/editor/document-editor/src/ui/components/links/link-edit-view.tsx b/packages/editor/document-editor/src/ui/components/links/link-edit-view.tsx
index 136d04e01e..9719154399 100644
--- a/packages/editor/document-editor/src/ui/components/links/link-edit-view.tsx
+++ b/packages/editor/document-editor/src/ui/components/links/link-edit-view.tsx
@@ -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;
};
@@ -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) => {