mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Improve Selection compatibility
collapse-30.html WPT test from from 2753/5133 to 5133/5133. -Return dom_exception from setPosition -Verify node containment in document
This commit is contained in:
@@ -457,6 +457,13 @@ pub fn ownerDocument(self: *const Node, page: *const Page) ?*Document {
|
||||
return page.document;
|
||||
}
|
||||
|
||||
pub fn isSameDocumentAs(self: *const Node, other: *const Node, page: *const Page) bool {
|
||||
// Get the root document for each node
|
||||
const self_doc = if (self._type == .document) self._type.document else self.ownerDocument(page);
|
||||
const other_doc = if (other._type == .document) other._type.document else other.ownerDocument(page);
|
||||
return self_doc == other_doc;
|
||||
}
|
||||
|
||||
pub fn hasChildNodes(self: *const Node) bool {
|
||||
return self.firstChild() != null;
|
||||
}
|
||||
|
||||
@@ -370,6 +370,11 @@ pub fn collapse(self: *Selection, _node: ?*Node, _offset: ?u32, page: *Page) !vo
|
||||
return error.IndexSizeError;
|
||||
}
|
||||
|
||||
// If the node is not contained in the document, do not change the selection
|
||||
if (!page.document.asNode().contains(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const range = try Range.init(page);
|
||||
try range.setStart(node, offset);
|
||||
try range.setEnd(node, offset);
|
||||
@@ -416,7 +421,7 @@ pub const JsApi = struct {
|
||||
pub const removeRange = bridge.function(Selection.removeRange, .{ .dom_exception = true });
|
||||
pub const selectAllChildren = bridge.function(Selection.selectAllChildren, .{});
|
||||
pub const setBaseAndExtent = bridge.function(Selection.setBaseAndExtent, .{ .dom_exception = true });
|
||||
pub const setPosition = bridge.function(Selection.collapse, .{});
|
||||
pub const setPosition = bridge.function(Selection.collapse, .{ .dom_exception = true });
|
||||
pub const toString = bridge.function(Selection.toString, .{});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user