Skip to content

Commit

Permalink
fix(editor): guard against erroneous undo/redo
Browse files Browse the repository at this point in the history
Before this change, if either undoing or redoing threw an error, the editor
would be stuck in the "preserve keys" state, causing duplicate keys to appear
everywhere, cascading into all sorts of problems and disruptive typing.
  • Loading branch information
christianhg committed Aug 16, 2024
1 parent e1dc9aa commit 53c3c61
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/editor/src/editor/plugins/createWithUndoRedo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {type Descendant, Editor, Operation, Path, type SelectionOperation, Trans
import {type PatchObservable, type PortableTextSlateEditor} from '../../types/editor'
import {debugWithName} from '../../utils/debug'
import {fromSlateValue} from '../../utils/values'
import {withPreserveKeys} from '../../utils/withPreserveKeys'
import {PRESERVE_KEYS, withPreserveKeys} from '../../utils/withPreserveKeys'

const debug = debugWithName('plugin:withUndoRedo')
const debugVerbose = debug.enabled && false
Expand Down Expand Up @@ -166,6 +166,7 @@ export function createWithUndoRedo(
Transforms.deselect(editor)
editor.history = {undos: [], redos: []}
SAVING.set(editor, true)
PRESERVE_KEYS.set(editor, false)
editor.onChange()
return
}
Expand Down Expand Up @@ -212,6 +213,7 @@ export function createWithUndoRedo(
Transforms.deselect(editor)
editor.history = {undos: [], redos: []}
SAVING.set(editor, true)
PRESERVE_KEYS.set(editor, false)
editor.onChange()
return
}
Expand Down

0 comments on commit 53c3c61

Please sign in to comment.