Skip to content

Commit 46ffb80

Browse files
authored
Merge pull request #1168 from lightpanda-io/dom_range_fixes
Reverses 2 incorrect comparions
2 parents 6f8c3ab + 163a0e8 commit 46ffb80

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/browser/dom/range.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub const Range = struct {
9292
pub fn _setStart(self: *Range, node: *parser.Node, offset_: i32) !void {
9393
try ensureValidOffset(node, offset_);
9494
const offset: u32 = @intCast(offset_);
95-
const position = compare(node, offset, self.proto.start_node, self.proto.start_offset) catch |err| switch (err) {
95+
const position = compare(node, offset, self.proto.end_node, self.proto.end_offset) catch |err| switch (err) {
9696
error.WrongDocument => blk: {
9797
// allow a node with a different root than the current, or
9898
// a disconnected one. Treat it as if it's "after", so that
@@ -103,7 +103,7 @@ pub const Range = struct {
103103
};
104104

105105
if (position == 1) {
106-
// if we're setting the node after the current start, the end must
106+
// if we're setting the node after the current end, the end must
107107
// be set too.
108108
self.proto.end_offset = offset;
109109
self.proto.end_node = node;
@@ -378,7 +378,7 @@ fn compare(node_a: *parser.Node, offset_a: u32, node_b: *parser.Node, offset_b:
378378

379379
const child_parent, const child_index = try getParentAndIndex(child);
380380
std.debug.assert(node_a == child_parent);
381-
return if (child_index < offset_a) -1 else 1;
381+
return if (offset_a <= child_index) -1 else 1;
382382
}
383383

384384
return -1;

0 commit comments

Comments
 (0)