fix(js): keep TreeWalker traversal in document order (#432)
This commit is contained in:
1 parent
29e20ae970
commit
c12915a1a6
4 files changed
+210
-12
No files matched your search
Vendored
+4
-12
@@ -2611,18 +2611,10 @@ class Document extends Node {
|
||||
return true;
|
||||
},
|
||||
nextNode() {
|
||||
let node = this.currentNode;
|
||||
let child = node.firstChild;
|
||||
while (child) {
|
||||
if (this._accept(child)) { this.currentNode = child; return child; }
|
||||
if (child.firstChild) { child = child.firstChild; continue; }
|
||||
if (child.nextSibling) { child = child.nextSibling; continue; }
|
||||
let parent = child.parentNode;
|
||||
while (parent && parent !== this.root) {
|
||||
if (parent.nextSibling) { child = parent.nextSibling; break; }
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
if (!parent || parent === this.root) return null;
|
||||
let node = _wrap(+_dom("next_in_subtree", this.root._nid, this.currentNode._nid));
|
||||
while (node) {
|
||||
if (this._accept(node)) { this.currentNode = node; return node; }
|
||||
node = _wrap(+_dom("next_in_subtree", this.root._nid, node._nid));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -268,6 +268,13 @@ fn op_dom_inner(state: &OpState, cmd: String, arg1: String, arg2: String) -> Str
|
||||
"prev_sibling" => n.prev_sibling, _ => None,
|
||||
}).flatten().map(|id| id.index().to_string()).unwrap_or("-1".into())
|
||||
}
|
||||
"next_in_subtree" => {
|
||||
let root = NodeId::new(arg1.parse::<u32>().unwrap_or(0));
|
||||
let current = NodeId::new(arg2.parse::<u32>().unwrap_or(0));
|
||||
dom.next_in_subtree(root, current)
|
||||
.map(|id| id.index().to_string())
|
||||
.unwrap_or("-1".into())
|
||||
}
|
||||
"child_nodes" => {
|
||||
let nid = arg1.parse::<u32>().unwrap_or(0);
|
||||
let ids: Vec<i32> = dom.children(NodeId::new(nid)).iter().map(|id| id.index() as i32).collect();
|
||||
|
||||
Reference in new issue
Block a user