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

fix: use ancestors for dirt paths (#2316)

* fix: use ancestors for dirt paths

Not just parents.

* fix: also revalidate ancestors when mutating existing nodes.
This commit is contained in:
Eric Edem
2018-10-24 16:06:53 -07:00
committed by Ian Storm Taylor
parent 611fa85b80
commit 2561ce4a89
2 changed files with 32 additions and 10 deletions

View File

@@ -326,26 +326,27 @@ function getDirtyPaths(operation) {
case 'remove_text':
case 'set_mark':
case 'set_node': {
return [path]
const ancestors = PathUtils.getAncestors(path).toArray()
return [...ancestors, path]
}
case 'insert_node': {
const table = node.getKeysToPathsTable()
const paths = Object.values(table).map(p => path.concat(p))
const parentPath = PathUtils.lift(path)
return [parentPath, path, ...paths]
const ancestors = PathUtils.getAncestors(path).toArray()
return [...ancestors, path, ...paths]
}
case 'split_node': {
const parentPath = PathUtils.lift(path)
const ancestors = PathUtils.getAncestors(path).toArray()
const nextPath = PathUtils.increment(path)
return [parentPath, path, nextPath]
return [...ancestors, path, nextPath]
}
case 'merge_node': {
const parentPath = PathUtils.lift(path)
const ancestors = PathUtils.getAncestors(path).toArray()
const previousPath = PathUtils.decrement(path)
return [parentPath, previousPath]
return [...ancestors, previousPath]
}
case 'move_node': {
@@ -364,12 +365,15 @@ function getDirtyPaths(operation) {
}
}
return [parentPath, newParentPath]
const oldAncestors = PathUtils.getAncestors(parentPath).toArray()
const newAncestors = PathUtils.getAncestors(newParentPath).toArray()
return [...oldAncestors, parentPath, ...newAncestors, newParentPath]
}
case 'remove_node': {
const parentPath = PathUtils.lift(path)
return [parentPath]
const ancestors = PathUtils.getAncestors(path).toArray()
return [...ancestors]
}
default: {

View File

@@ -76,6 +76,23 @@ function decrement(path, n = 1, index = path.size - 1) {
return increment(path, 0 - n, index)
}
/**
* Get all ancestor paths of th given path.
*
* @param {List} path
* @returns {List}
*/
function getAncestors(path) {
let ancestors = new List()
for (let i = 0; i < path.size; i++) {
ancestors = ancestors.push(path.slice(0, i))
}
return ancestors
}
/**
* Increment a `path` by `n` at `index`, defaulting to the last index.
*
@@ -358,6 +375,7 @@ export default {
create,
crop,
decrement,
getAncestors,
increment,
isAbove,
isAfter,