terminal2: sel adjust home/end

This commit is contained in:
Mitchell Hashimoto
2024-03-06 09:11:54 -08:00
parent 5c04ebe3bd
commit 7afe2e1eca

View File

@ -197,16 +197,28 @@ pub fn adjust(
// } else { // } else {
// result.end.y += screen.rows; // result.end.y += screen.rows;
// }, // },
//
// .home => { .home => self.end.* = s.pages.pin(.{ .screen = .{
// result.end.y = 0; .x = 0,
// result.end.x = 0; .y = 0,
// }, } }).?,
//
// .end => { .end => {
// result.end.y = screen_end; var it = s.pages.rowIterator(
// result.end.x = screen.cols - 1; .left_up,
//}, .{ .screen = .{} },
null,
);
while (it.next()) |next| {
const rac = next.rowAndCell();
const cells = next.page.data.getCells(rac.row);
if (page.Cell.hasTextAny(cells)) {
self.end.* = next;
self.end.x = cells.len - 1;
break;
}
}
},
else => @panic("TODO"), else => @panic("TODO"),
} }
@ -511,6 +523,64 @@ test "Selection: adjust down with not full screen" {
} }
} }
test "Selection: adjust home" {
const testing = std.testing;
var s = try Screen.init(testing.allocator, 5, 10, 0);
defer s.deinit();
try s.testWriteString("A\nB\nC");
// On the last line
{
var sel = try Selection.init(
&s,
s.pages.pin(.{ .screen = .{ .x = 4, .y = 1 } }).?,
s.pages.pin(.{ .screen = .{ .x = 1, .y = 2 } }).?,
false,
);
defer sel.deinit(&s);
sel.adjust(&s, .home);
// Start line
try testing.expectEqual(point.Point{ .screen = .{
.x = 4,
.y = 1,
} }, s.pages.pointFromPin(.screen, sel.start.*).?);
try testing.expectEqual(point.Point{ .screen = .{
.x = 0,
.y = 0,
} }, s.pages.pointFromPin(.screen, sel.end.*).?);
}
}
test "Selection: adjust end with not full screen" {
const testing = std.testing;
var s = try Screen.init(testing.allocator, 5, 10, 0);
defer s.deinit();
try s.testWriteString("A\nB\nC");
// On the last line
{
var sel = try Selection.init(
&s,
s.pages.pin(.{ .screen = .{ .x = 4, .y = 0 } }).?,
s.pages.pin(.{ .screen = .{ .x = 1, .y = 1 } }).?,
false,
);
defer sel.deinit(&s);
sel.adjust(&s, .end);
// Start line
try testing.expectEqual(point.Point{ .screen = .{
.x = 4,
.y = 0,
} }, s.pages.pointFromPin(.screen, sel.start.*).?);
try testing.expectEqual(point.Point{ .screen = .{
.x = 4,
.y = 2,
} }, s.pages.pointFromPin(.screen, sel.end.*).?);
}
}
test "Selection: order, standard" { test "Selection: order, standard" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;