diff --git a/packages/slate-history/src/with-history.ts b/packages/slate-history/src/with-history.ts index 49568f5db..ec7954d23 100644 --- a/packages/slate-history/src/with-history.ts +++ b/packages/slate-history/src/with-history.ts @@ -104,7 +104,9 @@ export const withHistory = (editor: Editor): Editor => { undos.shift() } - history.redos = [] + if (shouldClear(op)) { + history.redos = [] + } } } @@ -172,3 +174,15 @@ const shouldOverwrite = ( return false } + +/** + * Check whether an operation should clear the redos stack. + */ + +const shouldClear = (op: Operation): boolean => { + if (op.type === 'set_selection') { + return false + } + + return true +}