properly return NotFoundError on removeRange

This commit is contained in:
Muki Kiboigo
2026-01-15 23:15:27 -08:00
parent 8291044abc
commit fa3a23134e
2 changed files with 5 additions and 3 deletions

View File

@@ -143,7 +143,7 @@
testing.expectEqual(range2, sel.getRangeAt(0));
// Removing non-existent range does nothing
sel.removeRange(range1);
testing.expectError('NotFoundError', () => { sel.removeRange(range1); });
testing.expectEqual(1, sel.rangeCount);
}
</script>

View File

@@ -99,13 +99,15 @@ pub fn addRange(self: *Selection, range: *Range, page: *Page) !void {
return try self._ranges.append(page.arena, range);
}
pub fn removeRange(self: *Selection, range: *Range) void {
pub fn removeRange(self: *Selection, range: *Range) !void {
for (self._ranges.items, 0..) |r, i| {
if (r == range) {
_ = self._ranges.orderedRemove(i);
return;
}
}
return error.NotFound;
}
fn removeAllRangesInner(self: *Selection, reset_direction: bool) void {
@@ -392,7 +394,7 @@ pub const JsApi = struct {
pub const getRangeAt = bridge.function(Selection.getRangeAt, .{ .dom_exception = true });
pub const modify = bridge.function(Selection.modify, .{});
pub const removeAllRanges = bridge.function(Selection.removeAllRanges, .{});
pub const removeRange = bridge.function(Selection.removeRange, .{});
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.setPosition, .{});