mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-19 05:31:56 +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,
|
editor: ReactEditor,
|
||||||
domRange: DOMRange
|
domRange: DOMRange
|
||||||
) => {
|
) => {
|
||||||
const leafEl = domRange.startContainer.parentElement!
|
// This was affecting the selection of multiple blocks and dragging behavior,
|
||||||
leafEl.getBoundingClientRect = domRange.getBoundingClientRect.bind(domRange)
|
// so enabled only if the selection has been collapsed.
|
||||||
scrollIntoView(leafEl, {
|
if (
|
||||||
scrollMode: 'if-needed',
|
!editor.selection ||
|
||||||
})
|
(editor.selection && Range.isCollapsed(editor.selection))
|
||||||
delete leafEl.getBoundingClientRect
|
) {
|
||||||
|
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