1
0
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:
Soreine
2016-11-07 16:56:52 +01:00
parent 1112066b17
commit c644e8d220
2 changed files with 12 additions and 5 deletions

View File

@@ -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
},
/**

View File

@@ -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)
}
}