mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix an off by one in set cursor pos
This commit is contained in:
@ -426,7 +426,7 @@ pub fn reverseIndex(self: *Terminal) !void {
|
|||||||
// the right-most column. If row is 0, it is adjusted to 1. If row is
|
// the right-most column. If row is 0, it is adjusted to 1. If row is
|
||||||
// greater than the bottom-most row it is adjusted to the bottom-most
|
// greater than the bottom-most row it is adjusted to the bottom-most
|
||||||
// row.
|
// row.
|
||||||
pub fn setCursorPos(self: *Terminal, row: usize, col: usize) void {
|
pub fn setCursorPos(self: *Terminal, row_req: usize, col_req: usize) void {
|
||||||
// If cursor origin mode is set the cursor row will be moved relative to
|
// If cursor origin mode is set the cursor row will be moved relative to
|
||||||
// the top margin row and adjusted to be above or at bottom-most row in
|
// the top margin row and adjusted to be above or at bottom-most row in
|
||||||
// the current scroll region.
|
// the current scroll region.
|
||||||
@ -441,14 +441,16 @@ pub fn setCursorPos(self: *Terminal, row: usize, col: usize) void {
|
|||||||
y_max: usize,
|
y_max: usize,
|
||||||
} = if (self.modes.origin == 1) .{
|
} = if (self.modes.origin == 1) .{
|
||||||
.x_offset = 0, // TODO: left/right margins
|
.x_offset = 0, // TODO: left/right margins
|
||||||
|
.y_offset = self.scrolling_region.top,
|
||||||
.x_max = self.cols, // TODO: left/right margins
|
.x_max = self.cols, // TODO: left/right margins
|
||||||
.y_offset = self.scrolling_region.top + 1,
|
|
||||||
.y_max = self.scrolling_region.bottom + 1, // We need this 1-indexed
|
.y_max = self.scrolling_region.bottom + 1, // We need this 1-indexed
|
||||||
} else .{
|
} else .{
|
||||||
.x_max = self.cols,
|
.x_max = self.cols,
|
||||||
.y_max = self.rows,
|
.y_max = self.rows,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const row = if (row_req == 0) 1 else row_req;
|
||||||
|
const col = if (col_req == 0) 1 else col_req;
|
||||||
self.screen.cursor.x = @minimum(params.x_max, col) -| 1;
|
self.screen.cursor.x = @minimum(params.x_max, col) -| 1;
|
||||||
self.screen.cursor.y = @minimum(params.y_max, row + params.y_offset) -| 1;
|
self.screen.cursor.y = @minimum(params.y_max, row + params.y_offset) -| 1;
|
||||||
// log.info("set cursor position: col={} row={}", .{ self.screen.cursor.x, self.screen.cursor.y });
|
// log.info("set cursor position: col={} row={}", .{ self.screen.cursor.x, self.screen.cursor.y });
|
||||||
@ -1114,6 +1116,10 @@ test "Terminal: setCursorPosition" {
|
|||||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||||
try testing.expectEqual(@as(usize, 9), t.screen.cursor.y);
|
try testing.expectEqual(@as(usize, 9), t.screen.cursor.y);
|
||||||
|
|
||||||
|
t.setCursorPos(1, 1);
|
||||||
|
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||||
|
try testing.expectEqual(@as(usize, 9), t.screen.cursor.y);
|
||||||
|
|
||||||
t.setCursorPos(100, 0);
|
t.setCursorPos(100, 0);
|
||||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||||
try testing.expectEqual(@as(usize, 79), t.screen.cursor.y);
|
try testing.expectEqual(@as(usize, 79), t.screen.cursor.y);
|
||||||
|
Reference in New Issue
Block a user