Skip to content

Commit

Permalink
Fix TreeWalker.nextNode
Browse files Browse the repository at this point in the history
  • Loading branch information
thoughtsunificator committed Oct 8, 2024
1 parent 176f46d commit 59bd8bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/bbdocument/treewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class TreeWalker {
if(previousNode !== this._rootNode) {
this._path.push(previousNode)
}
} else if(this.currentNode.nextSibling !== null && !this._path.includes(this.currentNode.nextSibling)) {
} else if(this.currentNode.nextSibling !== null &&
(this._rootBookmark === this.currentNode.parentNode || this._path.includes(this.currentNode.parentNode)) &&
!this._path.includes(this.currentNode.nextSibling)) {
this._path.push(this.currentNode.nextSibling)
this._currentNode = this.currentNode.nextSibling
} else {
Expand Down
15 changes: 14 additions & 1 deletion test/bbdocument/treewalker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ describe("treewalker", () => {
assert.strictEqual(nodeList[13].textContent, "9")
assert.strictEqual(nodeList[14].textContent, "Test")


})

it("nextNode_", () => {
Expand Down Expand Up @@ -96,6 +95,20 @@ describe("treewalker", () => {

})

it("nextNode____", () => {

const bbDocument = Parser.parse("[quote]1[quote][/quote][quote][/quote][/quote]")

let treeWalker = new TreeWalker(bbDocument.documentElement.childNodes[0].childNodes[1])
let nodeList = []
while(treeWalker.nextNode()) {
nodeList.push(treeWalker.currentNode)
}
assert.strictEqual(nodeList.length, 0)


})

it("nextNodeList", () => {

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

0 comments on commit 59bd8bd

Please sign in to comment.