Skip to content

Commit bd66bfa

Browse files
authored
fix: When text is selected from right to left and then replaced with input, onValueChange is not triggered. (#5957)
1 parent cc5a9d8 commit bd66bfa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.changeset/mean-pots-thank.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'slate-react': patch
3+
---
4+
5+
Fix: `onValueChange` was not triggered when replacing text after selecting it from right to left.

packages/slate-react/src/components/editable.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,18 @@ export const Editable = forwardRef(
692692
exactMatch: false,
693693
suppressThrow: false,
694694
})
695+
const flippedRange = {
696+
anchor: range.focus,
697+
focus: range.anchor,
698+
}
695699

696-
if (!selection || !Range.equals(selection, range)) {
700+
if (
701+
!selection ||
702+
!(
703+
Range.equals(selection, range) ||
704+
Range.equals(selection, flippedRange)
705+
)
706+
) {
697707
native = false
698708

699709
const selectionRef =

0 commit comments

Comments
 (0)