Skip to content

Commit

Permalink
fix schema normalizing to merge into history
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstormtaylor committed May 5, 2017
1 parent 5bde3b3 commit a17d707
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/plugins/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Plugin(options = {}) {

const newState = state.transform()
.normalize(schema)
.apply({ save: false })
.apply({ merge: true })

debug('onBeforeChange')
return newState
Expand Down
4 changes: 2 additions & 2 deletions src/transforms/on-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

export default function (state) {
return state
.transform()
.removeNodeByKey('b')
.apply()

.transform()
.undo()
.apply()
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

export default function (state) {
return state
.transform()
.removeNodeByKey('bb')
.removeNodeByKey('b')
.apply()

.transform()
.undo()
.apply()
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@

import assert from 'assert'

export default function (state) {
const { selection } = state

let next = state
return state
.transform()
.removeNodeByKey('key1')
.apply()

.transform()
.undo()
.apply()

return next
}

0 comments on commit a17d707

Please sign in to comment.