1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-21 14:41:23 +02:00
This commit is contained in:
Ian Storm Taylor
2016-08-17 12:56:50 -07:00
parent cb204ae8e9
commit 8434850890
3 changed files with 25 additions and 42 deletions

View File

@@ -765,7 +765,6 @@ const Node = {
*/
getPath(key) {
debugger
key = Normalize.key(key)
if (key == this.key) return []

View File

@@ -76,6 +76,20 @@ class Transform {
return 'transform'
}
/**
* Add an `operation` to the transform that resulted in `state`.
*
* @param {State} state
* @param {Object} operation
* @return {Transform}
*/
add(state, operation) {
this.state = state
this.operations.push(operation)
return this
}
/**
* Apply the transform and return the new state.
*

View File

@@ -25,16 +25,13 @@ export function addMarkByKey(transform, key, offset, length, mark) {
document = document.updateDescendant(node)
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'add-mark',
offset,
length,
mark,
offset,
path,
})
return transform
}
/**
@@ -60,15 +57,12 @@ export function insertNodeByKey(transform, key, index, node) {
document = document.normalize()
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'insert-node',
index,
node,
path,
})
return transform
}
/**
@@ -92,16 +86,13 @@ export function insertTextByKey(transform, key, offset, text, marks) {
document = document.updateDescendant(node)
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'insert-text',
offset,
marks,
path,
text,
})
return transform
}
/**
@@ -135,15 +126,12 @@ export function moveNodeByKey(transform, key, newKey, newIndex) {
document = document.normalize()
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'move-node',
path,
newPath,
newIndex,
})
return transform
}
/**
@@ -169,16 +157,13 @@ export function removeMarkByKey(transform, key, offset, length, mark) {
document = document.updateDescendant(node)
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'remove-mark',
offset,
length,
mark,
path,
})
return transform
}
/**
@@ -203,13 +188,10 @@ export function removeNodeByKey(transform, key) {
document = document.normalize()
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'remove-node',
path,
})
return transform
}
/**
@@ -233,15 +215,12 @@ export function removeTextByKey(transform, key, offset, length) {
document = document.normalize()
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'remove-text',
offset,
length,
path,
})
return transform
}
/**
@@ -268,8 +247,7 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) {
document = document.updateDescendant(node)
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'set-mark',
offset,
length,
@@ -277,8 +255,6 @@ export function setMarkByKey(transform, key, offset, length, mark, properties) {
path,
properties,
})
return transform
}
/**
@@ -303,14 +279,11 @@ export function setNodeByKey(transform, key, properties) {
document = document.normalize()
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'set-node',
path,
properties,
})
return transform
}
/**
@@ -366,13 +339,10 @@ export function splitNodeByKey(transform, key, offset) {
document = isParent ? parent : document.updateDescendant(parent)
state = state.merge({ document })
transform.state = state
transform.operations.push({
return transform.add(state, {
type: 'split-node',
offset,
path,
})
return transform
}