From 8fd26ab591cabf171babcbb9cc0b8d69927deed8 Mon Sep 17 00:00:00 2001 From: ceekeywangxu Date: Thu, 21 Mar 2019 17:49:45 +0800 Subject: [PATCH] fixed nodesBetween when child is undefinded bug --- src/fragment.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/fragment.js b/src/fragment.js index d1e27d7..64897e5 100644 --- a/src/fragment.js +++ b/src/fragment.js @@ -22,14 +22,19 @@ export class Fragment { // into a node when the callback returns `false`. nodesBetween(from, to, f, nodeStart = 0, parent) { for (let i = 0, pos = 0; pos < to; i++) { - let child = this.content[i], end = pos + child.nodeSize - if (end > from && f(child, nodeStart + pos, parent, i) !== false && child.content.size) { - let start = pos + 1 - child.nodesBetween(Math.max(0, from - start), - Math.min(child.content.size, to - start), - f, nodeStart + start) + let child = this.content[i] + if (child) { + let end = pos + child.nodeSize + if (end > from && f(child, nodeStart + pos, parent, i) !== false && child.content.size) { + let start = pos + 1 + child.nodesBetween(Math.max(0, from - start), + Math.min(child.content.size, to - start), + f, nodeStart + start) + } + pos = end + } else { + pos = to } - pos = end } }