From e28b76b709b3d026dd66aaee29166416fca2e035 Mon Sep 17 00:00:00 2001 From: Soreine Date: Mon, 7 Nov 2016 18:41:51 +0100 Subject: [PATCH] Improve performance for Selection.hasEdgeIn methods --- src/models/selection.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/models/selection.js b/src/models/selection.js index 0f0bdd2e1..4065e00c6 100644 --- a/src/models/selection.js +++ b/src/models/selection.js @@ -190,8 +190,11 @@ class Selection extends new Record(DEFAULTS) { */ hasAnchorIn(node) { - const nodes = node.kind == 'text' ? [node] : node.getTexts() - return nodes.some(n => n.key == this.anchorKey) + if (node.kind == 'text') { + return node.key === this.anchorKey + } else { + return node.hasDescendant(this.anchorKey) + } } /** @@ -245,8 +248,11 @@ class Selection extends new Record(DEFAULTS) { */ hasFocusIn(node) { - const nodes = node.kind == 'text' ? [node] : node.getTexts() - return nodes.some(n => n.key == this.focusKey) + if (node.kind == 'text') { + return node.key === this.focusKey + } else { + return node.hasDescendant(this.focusKey) + } } /**