Skip to content

Commit 59bd8bd

Browse files
Fix TreeWalker.nextNode
1 parent 176f46d commit 59bd8bd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/bbdocument/treewalker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ class TreeWalker {
3939
if(previousNode !== this._rootNode) {
4040
this._path.push(previousNode)
4141
}
42-
} else if(this.currentNode.nextSibling !== null && !this._path.includes(this.currentNode.nextSibling)) {
42+
} else if(this.currentNode.nextSibling !== null &&
43+
(this._rootBookmark === this.currentNode.parentNode || this._path.includes(this.currentNode.parentNode)) &&
44+
!this._path.includes(this.currentNode.nextSibling)) {
4345
this._path.push(this.currentNode.nextSibling)
4446
this._currentNode = this.currentNode.nextSibling
4547
} else {

test/bbdocument/treewalker.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ describe("treewalker", () => {
5151
assert.strictEqual(nodeList[13].textContent, "9")
5252
assert.strictEqual(nodeList[14].textContent, "Test")
5353

54-
5554
})
5655

5756
it("nextNode_", () => {
@@ -96,6 +95,20 @@ describe("treewalker", () => {
9695

9796
})
9897

98+
it("nextNode____", () => {
99+
100+
const bbDocument = Parser.parse("[quote]1[quote][/quote][quote][/quote][/quote]")
101+
102+
let treeWalker = new TreeWalker(bbDocument.documentElement.childNodes[0].childNodes[1])
103+
let nodeList = []
104+
while(treeWalker.nextNode()) {
105+
nodeList.push(treeWalker.currentNode)
106+
}
107+
assert.strictEqual(nodeList.length, 0)
108+
109+
110+
})
111+
99112
it("nextNodeList", () => {
100113

101114
const bbDocument = Parser.parse("[list][*]1[list][*]test[/list][*]2[*]3[*]4[/list]")

0 commit comments

Comments
 (0)