From 5395931680186924f7efe74547eaca256f14e8ef Mon Sep 17 00:00:00 2001 From: CameronAckermanSEL Date: Tue, 4 Dec 2018 11:11:22 -0800 Subject: [PATCH] undo and redo operations are now wrapped with withoutNormalizing call to prevent normalizing occuring in between application or reversal of batched operations (#2462) --- packages/slate/src/commands/on-history.js | 72 ++++++++++++----------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/packages/slate/src/commands/on-history.js b/packages/slate/src/commands/on-history.js index 65c241997..36645ec3d 100644 --- a/packages/slate/src/commands/on-history.js +++ b/packages/slate/src/commands/on-history.js @@ -75,24 +75,26 @@ Commands.redo = editor => { if (!batch) return editor.withoutSaving(() => { - // Replay the batch of operations. - batch.forEach(op => { - const { type, properties } = op + editor.withoutNormalizing(() => { + // Replay the batch of operations. + batch.forEach(op => { + const { type, properties } = op - // When the operation mutates the selection, omit its `isFocused` value to - // prevent the editor focus from changing during redoing. - if (type === 'set_selection') { - op = op.set('properties', omit(properties, 'isFocused')) - } + // When the operation mutates the selection, omit its `isFocused` value to + // prevent the editor focus from changing during redoing. + if (type === 'set_selection') { + op = op.set('properties', omit(properties, 'isFocused')) + } - editor.applyOperation(op) + editor.applyOperation(op) + }) + + // Shift the next value into the undo stack. + redos = redos.pop() + undos = undos.push(batch) + const newData = data.set('undos', undos).set('redos', redos) + editor.setData(newData) }) - - // Shift the next value into the undo stack. - redos = redos.pop() - undos = undos.push(batch) - const newData = data.set('undos', undos).set('redos', redos) - editor.setData(newData) }) } @@ -111,28 +113,30 @@ Commands.undo = editor => { if (!batch) return editor.withoutSaving(() => { - // Replay the inverse of the previous operations. - batch - .slice() - .reverse() - .map(op => op.invert()) - .forEach(inverse => { - const { type, properties } = inverse + editor.withoutNormalizing(() => { + // Replay the inverse of the previous operations. + batch + .slice() + .reverse() + .map(op => op.invert()) + .forEach(inverse => { + const { type, properties } = inverse - // When the operation mutates the selection, omit its `isFocused` value to - // prevent the editor focus from changing during undoing. - if (type === 'set_selection') { - inverse = inverse.set('properties', omit(properties, 'isFocused')) - } + // When the operation mutates the selection, omit its `isFocused` value to + // prevent the editor focus from changing during undoing. + if (type === 'set_selection') { + inverse = inverse.set('properties', omit(properties, 'isFocused')) + } - editor.applyOperation(inverse) - }) + editor.applyOperation(inverse) + }) - // Shift the previous operations into the redo stack. - redos = redos.push(batch) - undos = undos.pop() - const newData = data.set('undos', undos).set('redos', redos) - editor.setData(newData) + // Shift the previous operations into the redo stack. + redos = redos.push(batch) + undos = undos.pop() + const newData = data.set('undos', undos).set('redos', redos) + editor.setData(newData) + }) }) }