-
Notifications
You must be signed in to change notification settings - Fork 67
ghostty: add ghostty_surface_set_selection_range C API #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2118,6 +2118,30 @@ pub fn selectCursorLine(self: *Surface) !bool { | |||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Set a selection range from buffer (screen) coordinates (cmux-specific). | ||||||||||||||||||||||||||||||||||
| pub fn setSelectionRange( | ||||||||||||||||||||||||||||||||||
| self: *Surface, | ||||||||||||||||||||||||||||||||||
| row_start: u32, | ||||||||||||||||||||||||||||||||||
| col_start: u32, | ||||||||||||||||||||||||||||||||||
| row_end: u32, | ||||||||||||||||||||||||||||||||||
| col_end: u32, | ||||||||||||||||||||||||||||||||||
| is_rectangular: bool, | ||||||||||||||||||||||||||||||||||
| ) !bool { | ||||||||||||||||||||||||||||||||||
| self.renderer_state.mutex.lock(); | ||||||||||||||||||||||||||||||||||
| defer self.renderer_state.mutex.unlock(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const screen: *terminal.Screen = self.io.terminal.screens.active; | ||||||||||||||||||||||||||||||||||
| const col_start_cell = std.math.cast(terminal.size.CellCountInt, col_start) orelse return false; | ||||||||||||||||||||||||||||||||||
| const col_end_cell = std.math.cast(terminal.size.CellCountInt, col_end) orelse return false; | ||||||||||||||||||||||||||||||||||
| const start_pin = screen.pages.pin(.{ .screen = .{ .x = col_start_cell, .y = row_start } }) orelse return false; | ||||||||||||||||||||||||||||||||||
| const end_pin = screen.pages.pin(.{ .screen = .{ .x = col_end_cell, .y = row_end } }) orelse return false; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| try self.setSelection(terminal.Selection.init(start_pin, end_pin, is_rectangular)); | ||||||||||||||||||||||||||||||||||
| screen.dirty.selection = true; | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+2136
to
+2140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize selection endpoints before constructing the selection. Line 2139 uses caller-provided start/end as-is. Reversed coordinates can violate the start≤end selection contract and produce incorrect selection behavior. Normalize pins first. Proposed fix const start_pin = screen.pages.pin(.{ .screen = .{ .x = col_start_cell, .y = row_start } }) orelse return false;
const end_pin = screen.pages.pin(.{ .screen = .{ .x = col_end_cell, .y = row_end } }) orelse return false;
- try self.setSelection(terminal.Selection.init(start_pin, end_pin, is_rectangular));
+ var ordered_start = start_pin;
+ var ordered_end = end_pin;
+ if (ordered_end.before(ordered_start)) {
+ std.mem.swap(terminal.Pin, &ordered_start, &ordered_end);
+ }
+
+ try self.setSelection(terminal.Selection.init(ordered_start, ordered_end, is_rectangular));📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| try self.queueRender(); | ||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Clear the active selection (cmux-specific). | ||||||||||||||||||||||||||||||||||
| pub fn clearSelection(self: *Surface) !bool { | ||||||||||||||||||||||||||||||||||
| self.renderer_state.mutex.lock(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_targuments. With four consecutive same-typed params the argument order (row_start, col_start, row_end, col_end) is invisible at the call site, and callers must read the implementation to determine it. Other single-uint32_tfunctions in this header are unambiguous, but this one is not. Adding names matches how Zig defines it and prevents accidental row/column transposition.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!