mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
terminal2: selection adjust right
This commit is contained in:
@ -1546,7 +1546,14 @@ pub fn cellIterator(
|
|||||||
) CellIterator {
|
) CellIterator {
|
||||||
var row_it = self.rowIterator(direction, tl_pt, bl_pt);
|
var row_it = self.rowIterator(direction, tl_pt, bl_pt);
|
||||||
var cell = row_it.next() orelse return .{ .row_it = row_it };
|
var cell = row_it.next() orelse return .{ .row_it = row_it };
|
||||||
if (direction == .left_up) cell.x = cell.page.data.size.cols - 1;
|
cell.x = switch (direction) {
|
||||||
|
.right_down => tl_pt.coord().x,
|
||||||
|
.left_up => if (bl_pt) |pt|
|
||||||
|
pt.coord().x
|
||||||
|
else
|
||||||
|
cell.page.data.size.cols - 1,
|
||||||
|
};
|
||||||
|
|
||||||
return .{ .row_it = row_it, .cell = cell };
|
return .{ .row_it = row_it, .cell = cell };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +120,6 @@ pub fn adjust(
|
|||||||
s: *const Screen,
|
s: *const Screen,
|
||||||
adjustment: Adjustment,
|
adjustment: Adjustment,
|
||||||
) void {
|
) void {
|
||||||
_ = self;
|
|
||||||
_ = s;
|
|
||||||
|
|
||||||
//const screen_end = Screen.RowIndexTag.screen.maxLen(screen) - 1;
|
//const screen_end = Screen.RowIndexTag.screen.maxLen(screen) - 1;
|
||||||
|
|
||||||
// Note that we always adjusts "end" because end always represents
|
// Note that we always adjusts "end" because end always represents
|
||||||
@ -162,28 +159,24 @@ pub fn adjust(
|
|||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// .right => {
|
.right => {
|
||||||
// // Step right, wrapping to the next row down at the start of each new line,
|
// Step right, wrapping to the next row down at the start of each new line,
|
||||||
// // until we find a non-empty cell.
|
// until we find a non-empty cell.
|
||||||
// var iterator = result.end.iterator(screen, .right_down);
|
var it = s.pages.cellIterator(
|
||||||
// _ = iterator.next();
|
.right_down,
|
||||||
// while (iterator.next()) |next| {
|
s.pages.pointFromPin(.screen, self.end.*).?,
|
||||||
// if (next.y > screen_end) break;
|
null,
|
||||||
// if (screen.getCell(
|
);
|
||||||
// .screen,
|
_ = it.next();
|
||||||
// next.y,
|
while (it.next()) |next| {
|
||||||
// next.x,
|
const rac = next.rowAndCell();
|
||||||
// ).char != 0) {
|
if (rac.cell.hasText()) {
|
||||||
// if (next.y > screen_end) {
|
self.end.* = next;
|
||||||
// result.end.y = screen_end;
|
break;
|
||||||
// } else {
|
}
|
||||||
// result.end = next;
|
}
|
||||||
// }
|
},
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
//
|
|
||||||
// .page_up => if (screen.rows > result.end.y) {
|
// .page_up => if (screen.rows > result.end.y) {
|
||||||
// result.end.y = 0;
|
// result.end.y = 0;
|
||||||
// result.end.x = 0;
|
// result.end.x = 0;
|
||||||
@ -218,52 +211,68 @@ test "Selection: adjust right" {
|
|||||||
defer s.deinit();
|
defer s.deinit();
|
||||||
try s.testWriteString("A1234\nB5678\nC1234\nD5678");
|
try s.testWriteString("A1234\nB5678\nC1234\nD5678");
|
||||||
|
|
||||||
// // Simple movement right
|
// Simple movement right
|
||||||
// {
|
{
|
||||||
// var sel = try Selection.init(
|
var sel = try Selection.init(
|
||||||
// &s,
|
&s,
|
||||||
// s.pages.pin(.{ .screen = .{ .x = 5, .y = 1 } }).?,
|
s.pages.pin(.{ .screen = .{ .x = 5, .y = 1 } }).?,
|
||||||
// s.pages.pin(.{ .screen = .{ .x = 3, .y = 3 } }).?,
|
s.pages.pin(.{ .screen = .{ .x = 3, .y = 3 } }).?,
|
||||||
// false,
|
false,
|
||||||
// );
|
);
|
||||||
// defer sel.deinit(&s);
|
defer sel.deinit(&s);
|
||||||
// sel.adjust(&s, .right);
|
sel.adjust(&s, .right);
|
||||||
//
|
|
||||||
// try testing.expectEqual(point.Point{ .screen = .{
|
|
||||||
// .x = 5,
|
|
||||||
// .y = 1,
|
|
||||||
// } }, s.pages.pointFromPin(.screen, sel.start.*).?);
|
|
||||||
// try testing.expectEqual(point.Point{ .screen = .{
|
|
||||||
// .x = 4,
|
|
||||||
// .y = 3,
|
|
||||||
// } }, s.pages.pointFromPin(.screen, sel.end.*).?);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Already at end of the line.
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
// {
|
.x = 5,
|
||||||
// const sel = (Selection{
|
.y = 1,
|
||||||
// .start = .{ .x = 5, .y = 1 },
|
} }, s.pages.pointFromPin(.screen, sel.start.*).?);
|
||||||
// .end = .{ .x = 4, .y = 2 },
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
// }).adjust(&screen, .right);
|
.x = 4,
|
||||||
//
|
.y = 3,
|
||||||
// try testing.expectEqual(Selection{
|
} }, s.pages.pointFromPin(.screen, sel.end.*).?);
|
||||||
// .start = .{ .x = 5, .y = 1 },
|
}
|
||||||
// .end = .{ .x = 0, .y = 3 },
|
|
||||||
// }, sel);
|
// Already at end of the line.
|
||||||
// }
|
{
|
||||||
//
|
var sel = try Selection.init(
|
||||||
// // Already at end of the screen
|
&s,
|
||||||
// {
|
s.pages.pin(.{ .screen = .{ .x = 4, .y = 1 } }).?,
|
||||||
// const sel = (Selection{
|
s.pages.pin(.{ .screen = .{ .x = 4, .y = 2 } }).?,
|
||||||
// .start = .{ .x = 5, .y = 1 },
|
false,
|
||||||
// .end = .{ .x = 4, .y = 3 },
|
);
|
||||||
// }).adjust(&screen, .right);
|
defer sel.deinit(&s);
|
||||||
//
|
sel.adjust(&s, .right);
|
||||||
// try testing.expectEqual(Selection{
|
|
||||||
// .start = .{ .x = 5, .y = 1 },
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
// .end = .{ .x = 4, .y = 3 },
|
.x = 4,
|
||||||
// }, sel);
|
.y = 1,
|
||||||
// }
|
} }, s.pages.pointFromPin(.screen, sel.start.*).?);
|
||||||
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
|
.x = 0,
|
||||||
|
.y = 3,
|
||||||
|
} }, s.pages.pointFromPin(.screen, sel.end.*).?);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already at end of the screen
|
||||||
|
{
|
||||||
|
var sel = try Selection.init(
|
||||||
|
&s,
|
||||||
|
s.pages.pin(.{ .screen = .{ .x = 5, .y = 1 } }).?,
|
||||||
|
s.pages.pin(.{ .screen = .{ .x = 4, .y = 3 } }).?,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
defer sel.deinit(&s);
|
||||||
|
sel.adjust(&s, .right);
|
||||||
|
|
||||||
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
|
.x = 5,
|
||||||
|
.y = 1,
|
||||||
|
} }, s.pages.pointFromPin(.screen, sel.start.*).?);
|
||||||
|
try testing.expectEqual(point.Point{ .screen = .{
|
||||||
|
.x = 4,
|
||||||
|
.y = 3,
|
||||||
|
} }, s.pages.pointFromPin(.screen, sel.end.*).?);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Selection: order, standard" {
|
test "Selection: order, standard" {
|
||||||
|
Reference in New Issue
Block a user