diff --git a/include/ghostty/vt/selection.h b/include/ghostty/vt/selection.h index d050f74ab..f71235a5a 100644 --- a/include/ghostty/vt/selection.h +++ b/include/ghostty/vt/selection.h @@ -178,7 +178,8 @@ typedef enum GHOSTTY_ENUM_TYPED { * @param selection Selection snapshot to adjust in place * @param adjustment The adjustment operation to apply * @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal, - * selection, selection references, or adjustment are invalid + * selection, or adjustment are invalid. Selection reference validity + * is a precondition and is not checked. * * @ingroup selection */ @@ -201,7 +202,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_adjust( * @param selection Selection snapshot to inspect * @param[out] out_order On success, receives the selection order * @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal, - * selection, selection references, or output pointer are invalid + * selection, or output pointer are invalid. Selection reference + * validity is a precondition and is not checked. * * @ingroup selection */ @@ -231,8 +233,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_order( * @param desired Desired endpoint order * @param[out] out_selection On success, receives the ordered selection * @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal, - * selection, selection references, desired order, or output pointer - * are invalid + * selection, desired order, or output pointer are invalid. Selection + * reference validity is a precondition and is not checked. * * @ingroup selection */ @@ -260,7 +262,8 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_ordered( * @param point Point to test for containment * @param[out] out_contains On success, receives whether point is inside selection * @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal, - * selection, selection references, point, or output pointer are invalid + * selection, point, or output pointer are invalid. Selection reference + * validity is a precondition and is not checked. * * @ingroup selection */ @@ -281,15 +284,16 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_contains( * for the given terminal's currently active screen. In practice, they must * come from that terminal and screen, and no mutating terminal call may have * occurred since the refs were produced or reconstructed from tracked refs. - * Passing refs from another terminal, another screen, or stale refs returns - * GHOSTTY_INVALID_VALUE. + * Passing refs from another terminal, another screen, or stale refs violates + * this precondition. * * @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE) * @param a First selection snapshot to compare * @param b Second selection snapshot to compare * @param[out] out_equal On success, receives whether the selections are equal * @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal, - * selections, selection references, or output pointer are invalid + * selections, or output pointer are invalid. Selection reference + * validity is a precondition and is not checked. * * @ingroup selection */ @@ -299,24 +303,6 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_equal( const GhosttySelection* b, bool* out_equal); -/** - * Validate that a selection snapshot is representable for a terminal. - * - * A valid selection has both endpoint grid refs resolved in the terminal's - * currently active screen/page list. Malformed refs, stale refs, refs from - * another terminal, or refs from an inactive screen return GHOSTTY_INVALID_VALUE. - * - * @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE) - * @param selection Selection snapshot to validate - * @return GHOSTTY_SUCCESS if the selection is valid for the terminal's active - * screen/page list, otherwise GHOSTTY_INVALID_VALUE - * - * @ingroup selection - */ -GHOSTTY_API GhosttyResult ghostty_terminal_selection_validate( - GhosttyTerminal terminal, - const GhosttySelection* selection); - /** @} */ #ifdef __cplusplus diff --git a/src/lib_vt.zig b/src/lib_vt.zig index 68aa4db63..cf3c2f820 100644 --- a/src/lib_vt.zig +++ b/src/lib_vt.zig @@ -244,7 +244,6 @@ comptime { @export(&c.terminal_selection_ordered, .{ .name = "ghostty_terminal_selection_ordered" }); @export(&c.terminal_selection_contains, .{ .name = "ghostty_terminal_selection_contains" }); @export(&c.terminal_selection_equal, .{ .name = "ghostty_terminal_selection_equal" }); - @export(&c.terminal_selection_validate, .{ .name = "ghostty_terminal_selection_validate" }); @export(&c.terminal_grid_ref, .{ .name = "ghostty_terminal_grid_ref" }); @export(&c.terminal_grid_ref_track, .{ .name = "ghostty_terminal_grid_ref_track" }); @export(&c.terminal_point_from_grid_ref, .{ .name = "ghostty_terminal_point_from_grid_ref" }); diff --git a/src/terminal/c/main.zig b/src/terminal/c/main.zig index 86898e7b9..19294d4a0 100644 --- a/src/terminal/c/main.zig +++ b/src/terminal/c/main.zig @@ -175,7 +175,6 @@ pub const terminal_selection_order = selection.order; pub const terminal_selection_ordered = selection.ordered; pub const terminal_selection_contains = selection.contains; pub const terminal_selection_equal = selection.equal; -pub const terminal_selection_validate = selection.validate; pub const terminal_grid_ref = terminal.grid_ref; pub const terminal_grid_ref_track = terminal.grid_ref_track; pub const terminal_point_from_grid_ref = terminal.point_from_grid_ref; diff --git a/src/terminal/c/selection.zig b/src/terminal/c/selection.zig index a5767609f..5734e9fb0 100644 --- a/src/terminal/c/selection.zig +++ b/src/terminal/c/selection.zig @@ -63,7 +63,6 @@ pub fn order( const sel = (selection orelse return .invalid_value).toZig() orelse return .invalid_value; const out = out_order orelse return .invalid_value; - if (!valid(t, sel)) return .invalid_value; out.* = sel.order(t.screens.active); return .success; @@ -86,7 +85,6 @@ pub fn ordered( const sel = (selection orelse return .invalid_value).toZig() orelse return .invalid_value; const out = out_selection orelse return .invalid_value; - if (!valid(t, sel)) return .invalid_value; out.* = .fromZig(sel.ordered(t.screens.active, desired)); return .success; @@ -102,7 +100,6 @@ pub fn contains( const sel = (selection orelse return .invalid_value).toZig() orelse return .invalid_value; const out = out_contains orelse return .invalid_value; - if (!valid(t, sel)) return .invalid_value; const screen = t.screens.active; const pin = screen.pages.pin(.fromC(pt)) orelse return .invalid_value; @@ -116,32 +113,13 @@ pub fn equal( b: ?*const CSelection, out_equal: ?*bool, ) callconv(lib.calling_conv) Result { - const t = terminal_c.zigTerminal(terminal) orelse return .invalid_value; + _ = terminal_c.zigTerminal(terminal) orelse return .invalid_value; const sel_a = (a orelse return .invalid_value).toZig() orelse return .invalid_value; const sel_b = (b orelse return .invalid_value).toZig() orelse return .invalid_value; const out = out_equal orelse return .invalid_value; - if (!valid(t, sel_a) or !valid(t, sel_b)) return .invalid_value; out.* = sel_a.eql(sel_b); return .success; } - -pub fn validate( - terminal: terminal_c.Terminal, - selection: ?*const CSelection, -) callconv(lib.calling_conv) Result { - const t = terminal_c.zigTerminal(terminal) orelse return .invalid_value; - const sel = (selection orelse return .invalid_value).toZig() orelse - return .invalid_value; - if (!valid(t, sel)) return .invalid_value; - - return .success; -} - -fn valid(t: *terminal_c.ZigTerminal, sel: Selection) bool { - const screen = t.screens.active; - return screen.pages.pointFromPin(.screen, sel.start()) != null and - screen.pages.pointFromPin(.screen, sel.end()) != null; -} diff --git a/src/terminal/c/terminal.zig b/src/terminal/c/terminal.zig index 3114f92ad..939b7a673 100644 --- a/src/terminal/c/terminal.zig +++ b/src/terminal/c/terminal.zig @@ -1552,7 +1552,7 @@ test "selection_contains" { try testing.expect(contains); } -test "selection_equal and selection_validate" { +test "selection_equal" { var t: Terminal = null; try testing.expectEqual(Result.success, new( &lib.alloc.test_allocator, @@ -1626,9 +1626,6 @@ test "selection_equal and selection_validate" { .end = cross_terminal_ref, }; - try testing.expectEqual(Result.success, selection_c.validate(t, &sel)); - try testing.expectEqual(Result.invalid_value, selection_c.validate(t, &cross_terminal)); - var equal: bool = undefined; try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &equal_sel, &equal)); try testing.expect(equal); @@ -1639,7 +1636,8 @@ test "selection_equal and selection_validate" { try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &different_rectangle, &equal)); try testing.expect(!equal); - try testing.expectEqual(Result.invalid_value, selection_c.equal(t, &sel, &cross_terminal, &equal)); + try testing.expectEqual(Result.success, selection_c.equal(t, &sel, &cross_terminal, &equal)); + try testing.expect(!equal); try testing.expectEqual(Result.invalid_value, selection_c.equal(t, &sel, &equal_sel, null)); }