WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit cd21bb1

Browse files
fix: sync state on undo when editor is unfocused (#5737)
* fix: undo event when not focused * chore: add changeset * Add `HistoryEditor.withMerging` to docs (#5738) * chore: just trigger test:integration * chore: trigger test:integration * fix: firefox test integration environment (#5742) * fix: fix firefox test integration env * chore: test ubuntu apt source * chore: IMMUTABLE_INSTALLS ? * fix: ubuntu version * fix: undo event when not focused * chore: add changeset * chore: just trigger test:integration * chore: trigger test:integration --------- Co-authored-by: Ty Mick <[email protected]>
1 parent 97ffee4 commit cd21bb1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

.changeset/curvy-seals-attack.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: sync built-in state on undo when editor is unfocused

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,8 +1042,31 @@ export const Editable = forwardRef(
10421042
op()
10431043
}
10441044
deferredOperations.current = []
1045+
1046+
// COMPAT: Since `beforeinput` doesn't fully `preventDefault`,
1047+
// there's a chance that content might be placed in the browser's undo stack.
1048+
// This means undo can be triggered even when the div is not focused,
1049+
// and it only triggers the input event for the node. (2024/10/09)
1050+
if (!ReactEditor.isFocused(editor)) {
1051+
const native = event.nativeEvent as InputEvent
1052+
const maybeHistoryEditor: any = editor
1053+
if (
1054+
native.inputType === 'historyUndo' &&
1055+
typeof maybeHistoryEditor.undo === 'function'
1056+
) {
1057+
maybeHistoryEditor.undo()
1058+
return
1059+
}
1060+
if (
1061+
native.inputType === 'historyRedo' &&
1062+
typeof maybeHistoryEditor.redo === 'function'
1063+
) {
1064+
maybeHistoryEditor.redo()
1065+
return
1066+
}
1067+
}
10451068
},
1046-
[attributes.onInput]
1069+
[attributes.onInput, editor]
10471070
)}
10481071
onBlur={useCallback(
10491072
(event: React.FocusEvent<HTMLDivElement>) => {

0 commit comments

Comments
 (0)