1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-01 04:50:27 +02:00

fix: default scroll selection (#4652)

* fix: default scroll selection

* feat: use Range.isCollapsed to check the selection

* chore: add changeset

* fix: grammer correction

* fix: grammer correction
This commit is contained in:
Karthikeyan
2021-11-16 14:51:14 +05:30
committed by GitHub
parent 7d9d25e179
commit 95389ed7b0
2 changed files with 18 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Disabled the auto scroll behaviour when the editor has any active selection

View File

@@ -1328,12 +1328,19 @@ const defaultScrollSelectionIntoView = (
editor: ReactEditor,
domRange: DOMRange
) => {
const leafEl = domRange.startContainer.parentElement!
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)
scrollIntoView(leafEl, {
scrollMode: 'if-needed',
})
delete leafEl.getBoundingClientRect
// This was affecting the selection of multiple blocks and dragging behavior,
// so enabled only if the selection has been collapsed.
if (
!editor.selection ||
(editor.selection && Range.isCollapsed(editor.selection))
) {
const leafEl = domRange.startContainer.parentElement!
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)
scrollIntoView(leafEl, {
scrollMode: 'if-needed',
})
delete leafEl.getBoundingClientRect
}
}
/**