@trafica/editor 1.0.38 → 1.0.39

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.
package/dist/index.mjs CHANGED
@@ -7847,6 +7847,7 @@ function EditorCore({
7847
7847
  }) {
7848
7848
  const containerRef = useRef(null);
7849
7849
  const isRenderingRef = useRef(false);
7850
+ const skipRestoreSelectionRef = useRef(false);
7850
7851
  const scrollCaretIntoView = useCallback(() => {
7851
7852
  var _a, _b;
7852
7853
  const sel = window.getSelection();
@@ -7959,8 +7960,14 @@ function EditorCore({
7959
7960
  useLayoutEffect(() => {
7960
7961
  const container = containerRef.current;
7961
7962
  if (!container || !state.selection) return;
7963
+ if (skipRestoreSelectionRef.current) {
7964
+ skipRestoreSelectionRef.current = false;
7965
+ return;
7966
+ }
7967
+ isRenderingRef.current = true;
7962
7968
  restoreSelection(container, state.selection);
7963
7969
  scrollCaretIntoView();
7970
+ isRenderingRef.current = false;
7964
7971
  }, [state.selection]);
7965
7972
  useEffect(() => {
7966
7973
  const container = containerRef.current;
@@ -8025,6 +8032,7 @@ function EditorCore({
8025
8032
  if (currentSelection && JSON.stringify(currentSelection.anchor) === JSON.stringify(captured.anchor) && JSON.stringify(currentSelection.focus) === JSON.stringify(captured.focus)) {
8026
8033
  return;
8027
8034
  }
8035
+ skipRestoreSelectionRef.current = true;
8028
8036
  const tr = createTransaction();
8029
8037
  tr.steps.push(tr_setSelection(captured));
8030
8038
  engine.dispatch(tr);
@@ -8407,10 +8415,9 @@ function EditorCore({
8407
8415
  if (!container) return;
8408
8416
  const selection = captureSelection(container);
8409
8417
  if (!selection) return;
8418
+ skipRestoreSelectionRef.current = true;
8410
8419
  const tr = createTransaction();
8411
- tr.steps.push(
8412
- tr_setSelection(selection)
8413
- );
8420
+ tr.steps.push(tr_setSelection(selection));
8414
8421
  engine.dispatch(tr);
8415
8422
  }, [engine]);
8416
8423
  const imageResizeRef = useRef(null);