mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 02:03:59 +02:00
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 <5317080+TyMick@users.noreply.github.com>
This commit is contained in:
@@ -1042,8 +1042,31 @@ export const Editable = forwardRef(
|
||||
op()
|
||||
}
|
||||
deferredOperations.current = []
|
||||
|
||||
// COMPAT: Since `beforeinput` doesn't fully `preventDefault`,
|
||||
// there's a chance that content might be placed in the browser's undo stack.
|
||||
// This means undo can be triggered even when the div is not focused,
|
||||
// and it only triggers the input event for the node. (2024/10/09)
|
||||
if (!ReactEditor.isFocused(editor)) {
|
||||
const native = event.nativeEvent as InputEvent
|
||||
const maybeHistoryEditor: any = editor
|
||||
if (
|
||||
native.inputType === 'historyUndo' &&
|
||||
typeof maybeHistoryEditor.undo === 'function'
|
||||
) {
|
||||
maybeHistoryEditor.undo()
|
||||
return
|
||||
}
|
||||
if (
|
||||
native.inputType === 'historyRedo' &&
|
||||
typeof maybeHistoryEditor.redo === 'function'
|
||||
) {
|
||||
maybeHistoryEditor.redo()
|
||||
return
|
||||
}
|
||||
}
|
||||
},
|
||||
[attributes.onInput]
|
||||
[attributes.onInput, editor]
|
||||
)}
|
||||
onBlur={useCallback(
|
||||
(event: React.FocusEvent<HTMLDivElement>) => {
|
||||
|
Reference in New Issue
Block a user