mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 06:31:28 +02:00
Retain editor selection when using ReactEditor.focus() (#5516)
* Retain editor selection on ReactEditor.focus() * Add changeset * Fix lint
This commit is contained in:
5
.changeset/selfish-frogs-press.md
Normal file
5
.changeset/selfish-frogs-press.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate-react': minor
|
||||
---
|
||||
|
||||
Retain editor selection when using ReactEditor.focus()
|
@@ -417,6 +417,12 @@ export const ReactEditor: ReactEditorInterface = {
|
||||
IS_FOCUSED.set(editor, true)
|
||||
|
||||
if (root.activeElement !== el) {
|
||||
if (editor.selection && root instanceof Document) {
|
||||
const domSelection = root.getSelection()
|
||||
const domRange = ReactEditor.toDOMRange(editor, editor.selection)
|
||||
domSelection?.removeAllRanges()
|
||||
domSelection?.addRange(domRange)
|
||||
}
|
||||
el.focus({ preventScroll: true })
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user