editor: fix position out of range error

This commit is contained in:
Ammar Ahmed
2024-04-04 11:47:18 +05:00
parent 6261f3f2c6
commit f671d2dec0

View File

@@ -39,7 +39,9 @@ export function TaskListComponent(
const checked = stats.total > 0 && stats.total === stats.checked; const checked = stats.total > 0 && stats.total === stats.checked;
const isNested = useMemo(() => { const isNested = useMemo(() => {
if (!pos || editor.state.doc.nodeSize < pos) return false; if (!pos || !(pos >= 0 && pos <= editor.state.doc.content.size))
return false;
return editor.state.doc.resolve(pos).parent.type.name === TaskItem.name; return editor.state.doc.resolve(pos).parent.type.name === TaskItem.name;
}, [editor.state.doc, pos]); }, [editor.state.doc, pos]);