mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 20:51:20 +02:00
Use getAncestors in getDescendant (#1604)
This commit is contained in:
committed by
Ian Storm Taylor
parent
3fa2fde253
commit
f28c59a26e
@@ -635,20 +635,10 @@ class Node {
|
|||||||
|
|
||||||
getDescendant(key) {
|
getDescendant(key) {
|
||||||
key = assertKey(key)
|
key = assertKey(key)
|
||||||
let descendantFound = null
|
// Use the cache by getAncestors
|
||||||
|
const ancestors = this.getAncestors(key)
|
||||||
const found = this.nodes.find((node) => {
|
if (!ancestors || ancestors.size === 0) return null
|
||||||
if (node.key === key) {
|
return ancestors.last().getChild(key)
|
||||||
return node
|
|
||||||
} else if (node.object !== 'text') {
|
|
||||||
descendantFound = node.getDescendant(key)
|
|
||||||
return descendantFound
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return descendantFound || found
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user