1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 23:12:52 +02:00

fix schema normalizing to merge into history

This commit is contained in:
Ian Storm Taylor
2017-05-05 09:01:15 -07:00
parent 5bde3b3ecd
commit a17d707665
9 changed files with 107 additions and 10 deletions

View File

@@ -56,7 +56,7 @@ function Plugin(options = {}) {
const newState = state.transform() const newState = state.transform()
.normalize(schema) .normalize(schema)
.apply({ save: false }) .apply({ merge: true })
debug('onBeforeChange') debug('onBeforeChange')
return newState return newState

View File

@@ -52,13 +52,13 @@ Transforms.save = (transform, options = {}) => {
let { state, operations } = transform let { state, operations } = transform
let { history } = state let { history } = state
let { undos, redos } = history let { undos, redos } = history
let previous = undos.peek()
// If there are no operations, abort. // If there are no operations, abort.
if (!operations.length) return if (!operations.length) return
// Create a new save point or merge the operations into the previous one. // Create a new save point or merge the operations into the previous one.
if (merge) { if (merge && previous) {
let previous = undos.peek()
undos = undos.pop() undos = undos.pop()
previous = previous.concat(operations) previous = previous.concat(operations)
undos = undos.push(previous) undos = undos.push(previous)

View File

@@ -0,0 +1,11 @@
export default function (state) {
return state
.transform()
.removeNodeByKey('b')
.apply()
.transform()
.undo()
.apply()
}

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,12 @@
export default function (state) {
return state
.transform()
.removeNodeByKey('bb')
.removeNodeByKey('b')
.apply()
.transform()
.undo()
.apply()
}

View File

@@ -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

View File

@@ -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

View File

@@ -1,10 +1,6 @@
import assert from 'assert'
export default function (state) { export default function (state) {
const { selection } = state return state
let next = state
.transform() .transform()
.removeNodeByKey('key1') .removeNodeByKey('key1')
.apply() .apply()
@@ -12,6 +8,4 @@ export default function (state) {
.transform() .transform()
.undo() .undo()
.apply() .apply()
return next
} }