mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 18:53:59 +02:00
@@ -1941,6 +1941,26 @@ const defaultScrollSelectionIntoView = (
|
||||
(editor.selection && Range.isCollapsed(editor.selection)))
|
||||
) {
|
||||
const leafEl = domRange.startContainer.parentElement!
|
||||
|
||||
// COMPAT: In Chrome, domRange.getBoundingClientRect() can return zero dimensions for valid ranges (e.g. line breaks).
|
||||
// When this happens, do not scroll like most editors do.
|
||||
const domRect = domRange.getBoundingClientRect()
|
||||
const isZeroDimensionRect =
|
||||
domRect.width === 0 &&
|
||||
domRect.height === 0 &&
|
||||
domRect.x === 0 &&
|
||||
domRect.y === 0
|
||||
|
||||
if (isZeroDimensionRect) {
|
||||
const leafRect = leafEl.getBoundingClientRect()
|
||||
const leafHasDimensions = leafRect.width > 0 || leafRect.height > 0
|
||||
|
||||
if (leafHasDimensions) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Default behavior: use domRange's getBoundingClientRect
|
||||
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)
|
||||
scrollIntoView(leafEl, {
|
||||
scrollMode: 'if-needed',
|
||||
|
Reference in New Issue
Block a user