slate-react 0.119.0 → 0.120.0-20251121000717

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.es.js CHANGED
@@ -3791,13 +3791,15 @@ var defaultDecorate = () => [];
3791
3791
  * A default implement to scroll dom range into view.
3792
3792
  */
3793
3793
  var defaultScrollSelectionIntoView = (editor, domRange) => {
3794
- // This was affecting the selection of multiple blocks and dragging behavior,
3795
- // so enabled only if the selection has been collapsed.
3796
- if (domRange.getBoundingClientRect && (!editor.selection || editor.selection && Range.isCollapsed(editor.selection))) {
3797
- var leafEl = domRange.startContainer.parentElement;
3798
- // COMPAT: In Chrome, domRange.getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
3794
+ // Scroll to the focus point of the selection, in case the selection is expanded
3795
+ var isBackward = !!editor.selection && Range.isBackward(editor.selection);
3796
+ var domFocusPoint = domRange.cloneRange();
3797
+ domFocusPoint.collapse(isBackward);
3798
+ if (domFocusPoint.getBoundingClientRect) {
3799
+ var leafEl = domFocusPoint.startContainer.parentElement;
3800
+ // COMPAT: In Chrome, domFocusPoint.getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
3799
3801
  // When this happens, do not scroll like most editors do.
3800
- var domRect = domRange.getBoundingClientRect();
3802
+ var domRect = domFocusPoint.getBoundingClientRect();
3801
3803
  var isZeroDimensionRect = domRect.width === 0 && domRect.height === 0 && domRect.x === 0 && domRect.y === 0;
3802
3804
  if (isZeroDimensionRect) {
3803
3805
  var leafRect = leafEl.getBoundingClientRect();
@@ -3806,8 +3808,8 @@ var defaultScrollSelectionIntoView = (editor, domRange) => {
3806
3808
  return;
3807
3809
  }
3808
3810
  }
3809
- // Default behavior: use domRange's getBoundingClientRect
3810
- leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange);
3811
+ // Default behavior: use domFocusPoint's getBoundingClientRect
3812
+ leafEl.getBoundingClientRect = domFocusPoint.getBoundingClientRect.bind(domFocusPoint);
3811
3813
  scrollIntoView(leafEl, {
3812
3814
  scrollMode: 'if-needed'
3813
3815
  });