Merge pull request #107 from mitchellh/trip-crash

terminal: selectLine can select last line with scrollback
This commit is contained in:
Mitchell Hashimoto
2023-03-17 11:09:13 -07:00
committed by GitHub

View File

@ -1175,7 +1175,7 @@ pub fn selectLine(self: *Screen, pt: point.ScreenPoint) ?Selection {
// The real end of the row is the final row in the soft-wrap.
const end_row: usize = end_row: {
var y: usize = pt.y;
while (y < y_max) : (y += 1) {
while (y <= y_max) : (y += 1) {
const current = self.getRow(.{ .screen = y });
if (y == y_max or !current.header().flags.wrap) break :end_row y;
}
@ -3060,6 +3060,33 @@ test "Screen: selectLine across soft-wrap ignores blank lines" {
}
}
test "Screen: selectLine with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 3, 2, 5);
defer s.deinit();
try s.testWriteString("1A\n2B\n3C\n4D\n5E");
// Selecting first line
{
const sel = s.selectLine(.{ .x = 0, .y = 0 }).?;
try testing.expectEqual(@as(usize, 0), sel.start.x);
try testing.expectEqual(@as(usize, 0), sel.start.y);
try testing.expectEqual(@as(usize, 1), sel.end.x);
try testing.expectEqual(@as(usize, 0), sel.end.y);
}
// Selecting last line
{
const sel = s.selectLine(.{ .x = 0, .y = 4 }).?;
try testing.expectEqual(@as(usize, 0), sel.start.x);
try testing.expectEqual(@as(usize, 4), sel.start.y);
try testing.expectEqual(@as(usize, 1), sel.end.x);
try testing.expectEqual(@as(usize, 4), sel.end.y);
}
}
test "Screen: selectWord" {
const testing = std.testing;
const alloc = testing.allocator;