mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-19 05:31:56 +02:00
Fix forEachDescendant early exit
This commit is contained in:
@@ -178,12 +178,19 @@ const Node = {
|
||||
*/
|
||||
|
||||
forEachDescendant(iterator) {
|
||||
return this.nodes.forEach((child, i, nodes) => {
|
||||
let returned // Returned value of iterator. False to break from loop
|
||||
|
||||
this.nodes.forEach((child, i, nodes) => {
|
||||
if (iterator(child, i, nodes) === false) {
|
||||
return false
|
||||
return returned = false
|
||||
}
|
||||
|
||||
if (child.kind != 'text') {
|
||||
return returned = child.forEachDescendant(iterator)
|
||||
}
|
||||
if (child.kind != 'text') child.forEachDescendant(iterator)
|
||||
})
|
||||
|
||||
return returned
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -332,10 +332,10 @@ class Selection extends new Record(DEFAULTS) {
|
||||
|
||||
// If `isBackward` is not set, derive it.
|
||||
if (isBackward == null) {
|
||||
if (anchorKey === focusKey) {
|
||||
if (anchorNode.key === focusNode.key) {
|
||||
isBackward = anchorOffset > focusOffset
|
||||
} else {
|
||||
isBackward = !node.areDescendantSorted(anchorKey, focusKey)
|
||||
isBackward = !node.areDescendantSorted(anchorNode.key, focusNode.key)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user