From af911fd0fff7e61e51f3f5cf790d514c71485567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 3 Nov 2016 17:03:46 +0100 Subject: [PATCH] Use Node.forEachDescendant in Node.findDescendantDeep --- src/models/node.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/models/node.js b/src/models/node.js index 052a6b863..8a17364ed 100644 --- a/src/models/node.js +++ b/src/models/node.js @@ -159,18 +159,16 @@ const Node = { */ findDescendantDeep(iterator) { - let descendantFound = null + let found - const found = this.nodes.find(node => { - if (node.kind != 'text') { - descendantFound = node.findDescendantDeep(iterator) - return descendantFound || iterator(node) + this.forEachDescendant(node => { + if (iterator(node)) { + found = node + return false } - - return iterator(node) ? node : null }) - return descendantFound || found + return found }, /**