@slate-yjs/core 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -77,6 +77,12 @@ export function withYHistory<T extends YjsEditor>(
77
77
  e.onChange = () => {
78
78
  onChange();
79
79
 
80
+ // Before connect the shared root may not match the Slate tree yet.
81
+ if (!YjsEditor.connected(e)) {
82
+ LAST_SELECTION.delete(e);
83
+ return;
84
+ }
85
+
80
86
  LAST_SELECTION.set(
81
87
  e,
82
88
  e.selection && slateRangeToRelativeRange(e.sharedRoot, e, e.selection)
@@ -103,8 +103,11 @@ export const YjsEditor = {
103
103
  withOrigin(editor: YjsEditor, origin: unknown, fn: () => void): void {
104
104
  const prev = YjsEditor.origin(editor);
105
105
  ORIGIN.set(editor, origin);
106
- fn();
107
- ORIGIN.set(editor, prev);
106
+ try {
107
+ fn();
108
+ } finally {
109
+ ORIGIN.set(editor, prev);
110
+ }
108
111
  },
109
112
 
110
113
  storePosition(editor: YjsEditor, key: string, point: Point): void {