1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

Fix autoscroll to top on line break (#5902)

* fix

* fix
This commit is contained in:
Ziad Beyens
2025-06-13 15:30:12 +02:00
committed by GitHub
parent 06b8822b9f
commit 47da9bf455
2 changed files with 25 additions and 0 deletions

View File

@@ -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',