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:
5
.changeset/green-penguins-check.md
Normal file
5
.changeset/green-penguins-check.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': patch
|
||||
---
|
||||
|
||||
Disabled the auto scroll behaviour when the editor has any active selection
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user