apply similar fix to selectAllChildren

This commit is contained in:
Karl Seguin
2026-02-10 12:23:41 +08:00
parent 1193ee1ab9
commit 1efd13545e

View File

@@ -313,12 +313,17 @@ pub fn modify(
} }
pub fn selectAllChildren(self: *Selection, parent: *Node, page: *Page) !void { pub fn selectAllChildren(self: *Selection, parent: *Node, page: *Page) !void {
if (parent._type == .document_type) return error.InvalidNodeTypeError; if (parent._type == .document_type) return error.InvalidNodeType;
// If the node is not contained in the document, do not change the selection
if (!page.document.asNode().contains(parent)) {
return;
}
const range = try Range.init(page); const range = try Range.init(page);
try range.setStart(parent, 0); try range.setStart(parent, 0);
const child_count = parent.getLength(); const child_count = parent.getChildrenCount();
try range.setEnd(parent, @intCast(child_count)); try range.setEnd(parent, @intCast(child_count));
self._range = range; self._range = range;
@@ -433,7 +438,7 @@ pub const JsApi = struct {
pub const modify = bridge.function(Selection.modify, .{}); pub const modify = bridge.function(Selection.modify, .{});
pub const removeAllRanges = bridge.function(Selection.removeAllRanges, .{}); pub const removeAllRanges = bridge.function(Selection.removeAllRanges, .{});
pub const removeRange = bridge.function(Selection.removeRange, .{ .dom_exception = true }); pub const removeRange = bridge.function(Selection.removeRange, .{ .dom_exception = true });
pub const selectAllChildren = bridge.function(Selection.selectAllChildren, .{}); pub const selectAllChildren = bridge.function(Selection.selectAllChildren, .{ .dom_exception = true });
pub const setBaseAndExtent = bridge.function(Selection.setBaseAndExtent, .{ .dom_exception = true }); pub const setBaseAndExtent = bridge.function(Selection.setBaseAndExtent, .{ .dom_exception = true });
pub const setPosition = bridge.function(Selection.collapse, .{ .dom_exception = true }); pub const setPosition = bridge.function(Selection.collapse, .{ .dom_exception = true });
pub const toString = bridge.function(Selection.toString, .{}); pub const toString = bridge.function(Selection.toString, .{});