1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-20 06:01:24 +02:00

undo and redo operations are now wrapped with withoutNormalizing call to prevent normalizing occuring in between application or reversal of batched operations (#2462)

This commit is contained in:
CameronAckermanSEL
2018-12-04 11:11:22 -08:00
committed by Ian Storm Taylor
parent 287875b9e3
commit 5395931680

View File

@@ -75,24 +75,26 @@ Commands.redo = editor => {
if (!batch) return if (!batch) return
editor.withoutSaving(() => { editor.withoutSaving(() => {
// Replay the batch of operations. editor.withoutNormalizing(() => {
batch.forEach(op => { // Replay the batch of operations.
const { type, properties } = op batch.forEach(op => {
const { type, properties } = op
// When the operation mutates the selection, omit its `isFocused` value to // When the operation mutates the selection, omit its `isFocused` value to
// prevent the editor focus from changing during redoing. // prevent the editor focus from changing during redoing.
if (type === 'set_selection') { if (type === 'set_selection') {
op = op.set('properties', omit(properties, 'isFocused')) 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 if (!batch) return
editor.withoutSaving(() => { editor.withoutSaving(() => {
// Replay the inverse of the previous operations. editor.withoutNormalizing(() => {
batch // Replay the inverse of the previous operations.
.slice() batch
.reverse() .slice()
.map(op => op.invert()) .reverse()
.forEach(inverse => { .map(op => op.invert())
const { type, properties } = inverse .forEach(inverse => {
const { type, properties } = inverse
// When the operation mutates the selection, omit its `isFocused` value to // When the operation mutates the selection, omit its `isFocused` value to
// prevent the editor focus from changing during undoing. // prevent the editor focus from changing during undoing.
if (type === 'set_selection') { if (type === 'set_selection') {
inverse = inverse.set('properties', omit(properties, 'isFocused')) inverse = inverse.set('properties', omit(properties, 'isFocused'))
} }
editor.applyOperation(inverse) editor.applyOperation(inverse)
}) })
// Shift the previous operations into the redo stack. // Shift the previous operations into the redo stack.
redos = redos.push(batch) redos = redos.push(batch)
undos = undos.pop() undos = undos.pop()
const newData = data.set('undos', undos).set('redos', redos) const newData = data.set('undos', undos).set('redos', redos)
editor.setData(newData) editor.setData(newData)
})
}) })
} }