characterdata: add previouselementSibling getter

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-10-02 17:29:27 +02:00
parent 202ee1646d
commit 7406b6d06c
2 changed files with 37 additions and 5 deletions

View File

@@ -270,14 +270,14 @@ pub fn nodeNextSibling(node: *Node) ?*Node {
pub fn nodeNextElementSibling(node: *Node) ?*Element {
var n = node;
while (true) {
const next = nodeNextSibling(n);
if (next == null) {
const res = nodeNextSibling(n);
if (res == null) {
return null;
}
if (nodeType(next.?) == .element) {
return @as(*Element, @ptrCast(next.?));
if (nodeType(res.?) == .element) {
return @as(*Element, @ptrCast(res.?));
}
n = next.?;
n = res.?;
}
return null;
}
@@ -288,6 +288,21 @@ pub fn nodePreviousSibling(node: *Node) ?*Node {
return res;
}
pub fn nodePreviousElementSibling(node: *Node) ?*Element {
var n = node;
while (true) {
const res = nodePreviousSibling(n);
if (res == null) {
return null;
}
if (nodeType(res.?) == .element) {
return @as(*Element, @ptrCast(res.?));
}
n = res.?;
}
return null;
}
pub fn nodeParentNode(node: *Node) ?*Node {
var res: ?*Node = undefined;
_ = nodeVtable(node).dom_node_get_parent_node.?(node, &res);