From 663522139cd8919a463956e933c3822fe3254704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 3 Nov 2016 12:05:16 +0100 Subject: [PATCH] Allow Node.forEachDescendant to exit early --- src/models/node.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/models/node.js b/src/models/node.js index 7f7483b1c..dff96ee50 100644 --- a/src/models/node.js +++ b/src/models/node.js @@ -170,7 +170,9 @@ const Node = { forEachDescendant(iterator) { return this.nodes.forEach((child, i, nodes) => { - iterator(child, i, nodes) + if (iterator(child, i, nodes) === false) { + return false + } if (child.kind != 'text') child.forEachDescendant(iterator) }) },