1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-20 05:09:43 +01:00

Collapse expanded selection before move word (#4211)

This commit is contained in:
Claudéric Demers 2021-05-03 15:29:27 -04:00 committed by GitHub
parent 737aaa9cde
commit 1c32b97d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'slate-react': patch
---
Collapse expanded selection before handling `moveWordBackward` (`alt + left`) and `moveWordForward` (`alt + right`) hotkeys.

View File

@ -915,12 +915,22 @@ export const Editable = (props: EditableProps) => {
if (Hotkeys.isMoveWordBackward(nativeEvent)) {
event.preventDefault()
if (selection && Range.isExpanded(selection)) {
Transforms.collapse(editor, { edge: 'focus' })
}
Transforms.move(editor, { unit: 'word', reverse: !isRTL })
return
}
if (Hotkeys.isMoveWordForward(nativeEvent)) {
event.preventDefault()
if (selection && Range.isExpanded(selection)) {
Transforms.collapse(editor, { edge: 'focus' })
}
Transforms.move(editor, { unit: 'word', reverse: isRTL })
return
}