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:
committed by
Ian Storm Taylor
parent
44eccca60a
commit
2a1da72c70
@@ -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`.
|
||||
*
|
||||
|
Reference in New Issue
Block a user