mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +02:00
5
.changeset/funny-mirrors-cough.md
Normal file
5
.changeset/funny-mirrors-cough.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes #5900
|
@@ -1941,6 +1941,26 @@ const defaultScrollSelectionIntoView = (
|
|||||||
(editor.selection && Range.isCollapsed(editor.selection)))
|
(editor.selection && Range.isCollapsed(editor.selection)))
|
||||||
) {
|
) {
|
||||||
const leafEl = domRange.startContainer.parentElement!
|
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)
|
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)
|
||||||
scrollIntoView(leafEl, {
|
scrollIntoView(leafEl, {
|
||||||
scrollMode: 'if-needed',
|
scrollMode: 'if-needed',
|
||||||
|
Reference in New Issue
Block a user