mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 15:23:29 -05:00
TreeWalker must not try to access parent of root node
This commit is contained in:
parent
183091e4e1
commit
c83688b630
1 changed files with 8 additions and 10 deletions
|
@ -76,15 +76,12 @@ TreeWalker.prototype.nextNode = function () {
|
|||
while ( true ) {
|
||||
node = current.firstChild;
|
||||
while ( !node && current ) {
|
||||
node = current.nextSibling;
|
||||
if ( !node ) {
|
||||
current = current.parentNode;
|
||||
if ( current === root ) {
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
node = current.nextSibling;
|
||||
if ( !node ) { current = current.parentNode; }
|
||||
}
|
||||
}
|
||||
|
||||
if ( !node ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -93,7 +90,6 @@ TreeWalker.prototype.nextNode = function () {
|
|||
this.currentNode = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
current = node;
|
||||
}
|
||||
};
|
||||
|
@ -105,7 +101,7 @@ TreeWalker.prototype.previousNode = function () {
|
|||
filter = this.filter,
|
||||
node;
|
||||
while ( true ) {
|
||||
if ( node === root ) {
|
||||
if ( current === root ) {
|
||||
return null;
|
||||
}
|
||||
node = current.previousSibling;
|
||||
|
@ -116,12 +112,14 @@ TreeWalker.prototype.previousNode = function () {
|
|||
} else {
|
||||
node = current.parentNode;
|
||||
}
|
||||
if ( !node ) {
|
||||
return null;
|
||||
}
|
||||
if ( ( typeToBitArray[ node.nodeType ] & nodeType ) &&
|
||||
filter( node ) === FILTER_ACCEPT ) {
|
||||
this.currentNode = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
current = node;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue