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

Use getAncestors in getDescendant (#1604)

This commit is contained in:
Jinxuan Zhu
2018-02-06 17:12:48 -05:00
committed by Ian Storm Taylor
parent 3fa2fde253
commit f28c59a26e

View File

@@ -635,20 +635,10 @@ class Node {
getDescendant(key) {
key = assertKey(key)
let descendantFound = null
const found = this.nodes.find((node) => {
if (node.key === key) {
return node
} else if (node.object !== 'text') {
descendantFound = node.getDescendant(key)
return descendantFound
} else {
return false
}
})
return descendantFound || found
// Use the cache by getAncestors
const ancestors = this.getAncestors(key)
if (!ancestors || ancestors.size === 0) return null
return ancestors.last().getChild(key)
}
/**