Skip to content

Commit

Permalink
Merge pull request #11 from LucasXu0/fix_#7
Browse files Browse the repository at this point in the history
fix: #7 bug on node iterator with nested nodes
  • Loading branch information
LucasXu0 authored Mar 15, 2023
2 parents cb8b763 + ab8a4fe commit c79d9a9
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lib/src/core/document/node_iterator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,30 @@ class NodeIterator implements Iterator<Node> {
return true;
}

final node = _currentNode;
if (node == null) {
if (_currentNode == null) {
return false;
}
Node node = _currentNode!;

if (endNode != null && endNode == node) {
_currentNode = null;
return false;
}

if (node.children.isNotEmpty) {
_currentNode = _findLeadingChild(node);
_currentNode = node.children.first;
} else if (node.next != null) {
_currentNode = node.next!;
} else {
final parent = node.parent!;
final nextOfParent = parent.next;
if (nextOfParent == null) {
_currentNode = null;
} else {
_currentNode = nextOfParent;
while (node.parent != null) {
node = node.parent!;
final nextOfParent = node.next;
if (nextOfParent == null) {
_currentNode = null;
} else {
_currentNode = nextOfParent;
break;
}
}
}

Expand All @@ -61,11 +64,4 @@ class NodeIterator implements Iterator<Node> {
}
return result;
}

Node _findLeadingChild(Node node) {
while (node.children.isNotEmpty) {
node = node.children.first;
}
return node;
}
}

0 comments on commit c79d9a9

Please sign in to comment.