1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 13:41:19 +02:00

Faster (but also safe) method about re-find node by path (#1548)

This commit is contained in:
Jinxuan Zhu
2018-01-30 21:05:43 -05:00
committed by Ian Storm Taylor
parent 44eccca60a
commit 2a1da72c70

View File

@@ -1351,6 +1351,41 @@ class Node {
return path
}
/**
* Refind the path of node if path is changed.
*
* @param {Array} path
* @param {String} key
* @return {Array}
*/
refindPath(path, key) {
const node = this.getDescendantAtPath(path)
if (node && node.key === key) {
return path
}
return this.getPath(key)
}
/**
*
* Refind the node with the same node.key after change.
*
* @param {Array} path
* @param {String} key
* @return {Node|Void}
*/
refindNode(path, key) {
const node = this.getDescendantAtPath(path)
if (node && node.key === key) {
return node
}
return this.getDescendant(key)
}
/**
* Get the placeholder for the node from a `schema`.
*