mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +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:
committed by
Ian Storm Taylor
parent
611fa85b80
commit
2561ce4a89
@@ -326,26 +326,27 @@ function getDirtyPaths(operation) {
|
|||||||
case 'remove_text':
|
case 'remove_text':
|
||||||
case 'set_mark':
|
case 'set_mark':
|
||||||
case 'set_node': {
|
case 'set_node': {
|
||||||
return [path]
|
const ancestors = PathUtils.getAncestors(path).toArray()
|
||||||
|
return [...ancestors, path]
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'insert_node': {
|
case 'insert_node': {
|
||||||
const table = node.getKeysToPathsTable()
|
const table = node.getKeysToPathsTable()
|
||||||
const paths = Object.values(table).map(p => path.concat(p))
|
const paths = Object.values(table).map(p => path.concat(p))
|
||||||
const parentPath = PathUtils.lift(path)
|
const ancestors = PathUtils.getAncestors(path).toArray()
|
||||||
return [parentPath, path, ...paths]
|
return [...ancestors, path, ...paths]
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'split_node': {
|
case 'split_node': {
|
||||||
const parentPath = PathUtils.lift(path)
|
const ancestors = PathUtils.getAncestors(path).toArray()
|
||||||
const nextPath = PathUtils.increment(path)
|
const nextPath = PathUtils.increment(path)
|
||||||
return [parentPath, path, nextPath]
|
return [...ancestors, path, nextPath]
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'merge_node': {
|
case 'merge_node': {
|
||||||
const parentPath = PathUtils.lift(path)
|
const ancestors = PathUtils.getAncestors(path).toArray()
|
||||||
const previousPath = PathUtils.decrement(path)
|
const previousPath = PathUtils.decrement(path)
|
||||||
return [parentPath, previousPath]
|
return [...ancestors, previousPath]
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'move_node': {
|
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': {
|
case 'remove_node': {
|
||||||
const parentPath = PathUtils.lift(path)
|
const ancestors = PathUtils.getAncestors(path).toArray()
|
||||||
return [parentPath]
|
return [...ancestors]
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
@@ -76,6 +76,23 @@ function decrement(path, n = 1, index = path.size - 1) {
|
|||||||
return increment(path, 0 - n, index)
|
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.
|
* Increment a `path` by `n` at `index`, defaulting to the last index.
|
||||||
*
|
*
|
||||||
@@ -358,6 +375,7 @@ export default {
|
|||||||
create,
|
create,
|
||||||
crop,
|
crop,
|
||||||
decrement,
|
decrement,
|
||||||
|
getAncestors,
|
||||||
increment,
|
increment,
|
||||||
isAbove,
|
isAbove,
|
||||||
isAfter,
|
isAfter,
|
||||||
|
Reference in New Issue
Block a user