mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 15:02:51 +02:00
fix schema normalizing to merge into history
This commit is contained in:
@@ -56,7 +56,7 @@ function Plugin(options = {}) {
|
||||
|
||||
const newState = state.transform()
|
||||
.normalize(schema)
|
||||
.apply({ save: false })
|
||||
.apply({ merge: true })
|
||||
|
||||
debug('onBeforeChange')
|
||||
return newState
|
||||
|
@@ -52,13 +52,13 @@ Transforms.save = (transform, options = {}) => {
|
||||
let { state, operations } = transform
|
||||
let { history } = state
|
||||
let { undos, redos } = history
|
||||
let previous = undos.peek()
|
||||
|
||||
// If there are no operations, abort.
|
||||
if (!operations.length) return
|
||||
|
||||
// Create a new save point or merge the operations into the previous one.
|
||||
if (merge) {
|
||||
let previous = undos.peek()
|
||||
if (merge && previous) {
|
||||
undos = undos.pop()
|
||||
previous = previous.concat(operations)
|
||||
undos = undos.push(previous)
|
||||
|
@@ -0,0 +1,11 @@
|
||||
|
||||
export default function (state) {
|
||||
return state
|
||||
.transform()
|
||||
.removeNodeByKey('b')
|
||||
.apply()
|
||||
|
||||
.transform()
|
||||
.undo()
|
||||
.apply()
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
key: a
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
key: b
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
key: c
|
||||
type: image
|
||||
isVoid: true
|
@@ -0,0 +1,14 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
key: a
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
key: b
|
||||
type: image
|
||||
isVoid: true
|
||||
- kind: block
|
||||
key: c
|
||||
type: image
|
||||
isVoid: true
|
@@ -0,0 +1,12 @@
|
||||
|
||||
export default function (state) {
|
||||
return state
|
||||
.transform()
|
||||
.removeNodeByKey('bb')
|
||||
.removeNodeByKey('b')
|
||||
.apply()
|
||||
|
||||
.transform()
|
||||
.undo()
|
||||
.apply()
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: figure
|
||||
key: a
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: aa
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: figure
|
||||
key: b
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: bb
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: figure
|
||||
key: c
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: cc
|
||||
isVoid: true
|
@@ -0,0 +1,26 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: figure
|
||||
key: a
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: aa
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: figure
|
||||
key: b
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: bb
|
||||
isVoid: true
|
||||
- kind: block
|
||||
type: figure
|
||||
key: c
|
||||
nodes:
|
||||
- kind: block
|
||||
type: image
|
||||
key: cc
|
||||
isVoid: true
|
@@ -1,10 +1,6 @@
|
||||
|
||||
import assert from 'assert'
|
||||
|
||||
export default function (state) {
|
||||
const { selection } = state
|
||||
|
||||
let next = state
|
||||
return state
|
||||
.transform()
|
||||
.removeNodeByKey('key1')
|
||||
.apply()
|
||||
@@ -12,6 +8,4 @@ export default function (state) {
|
||||
.transform()
|
||||
.undo()
|
||||
.apply()
|
||||
|
||||
return next
|
||||
}
|
||||
|
Reference in New Issue
Block a user