@@ -1952,18 +1952,17 @@ export const defaultScrollSelectionIntoView = (
19521952 editor : ReactEditor ,
19531953 domRange : DOMRange
19541954) => {
1955- // This was affecting the selection of multiple blocks and dragging behavior,
1956- // so enabled only if the selection has been collapsed.
1957- if (
1958- domRange . getBoundingClientRect &&
1959- ( ! editor . selection ||
1960- ( editor . selection && Range . isCollapsed ( editor . selection ) ) )
1961- ) {
1962- const leafEl = domRange . startContainer . parentElement !
1955+ // Scroll to the focus point of the selection, in case the selection is expanded
1956+ const isBackward = ! ! editor . selection && Range . isBackward ( editor . selection )
1957+ const domFocusPoint = domRange . cloneRange ( )
1958+ domFocusPoint . collapse ( isBackward )
1959+
1960+ if ( domFocusPoint . getBoundingClientRect ) {
1961+ const leafEl = domFocusPoint . startContainer . parentElement !
19631962
1964- // COMPAT: In Chrome, domRange .getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
1963+ // COMPAT: In Chrome, domFocusPoint .getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
19651964 // When this happens, do not scroll like most editors do.
1966- const domRect = domRange . getBoundingClientRect ( )
1965+ const domRect = domFocusPoint . getBoundingClientRect ( )
19671966 const isZeroDimensionRect =
19681967 domRect . width === 0 &&
19691968 domRect . height === 0 &&
@@ -1979,8 +1978,9 @@ export const defaultScrollSelectionIntoView = (
19791978 }
19801979 }
19811980
1982- // Default behavior: use domRange's getBoundingClientRect
1983- leafEl . getBoundingClientRect = domRange . getBoundingClientRect . bind ( domRange )
1981+ // Default behavior: use domFocusPoint's getBoundingClientRect
1982+ leafEl . getBoundingClientRect =
1983+ domFocusPoint . getBoundingClientRect . bind ( domFocusPoint )
19841984 scrollIntoView ( leafEl , {
19851985 scrollMode : 'if-needed' ,
19861986 } )
0 commit comments