fix: safely handles rich text deselection

This commit is contained in:
James
2022-12-15 12:39:57 -05:00
parent d2f281d318
commit 420eef4d91

View File

@@ -206,9 +206,10 @@ const RichText: React.FC<Props> = (props) => {
}, [loaded, readOnly]);
useEffect(() => {
// If there is a change to the initial value, we need to reset Slate
// to the new initial value, and clear selection
if (Array.isArray(initialValue) && initialValue.length > 0) {
const point = { path: [0, 0], offset: 0 };
editor.selection = { anchor: point, focus: point };
if (editor.selection) ReactEditor.deselect(editor);
editor.history = { redos: [], undos: [] };
editor.children = initialValue;
}