From 72d78f5a696aa8e94fe39cebdbd0d2efc8e5b244 Mon Sep 17 00:00:00 2001 From: Wee Date: Sun, 1 Dec 2019 06:21:24 +0800 Subject: [PATCH] fix: lost redos when trigger set_selection (fix #3140) (#3176) * fix: lost redos when trigger set_selection (fix #3140) * Update with-history.ts --- packages/slate-history/src/with-history.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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 +}