mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
terminal: more selection tests
This commit is contained in:
@ -4057,6 +4057,7 @@ test "Screen: scrollback doesn't move viewport if not at bottom" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// X
|
||||||
test "Screen: scrolling moves selection" {
|
test "Screen: scrolling moves selection" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -2125,6 +2125,85 @@ test "Screen: scrollback doesn't move viewport if not at bottom" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Screen: scrolling moves selection" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 5, 3, 1);
|
||||||
|
defer s.deinit();
|
||||||
|
try s.testWriteString("1ABCD\n2EFGH\n3IJKL");
|
||||||
|
|
||||||
|
// Select a single line
|
||||||
|
try s.select(Selection.init(
|
||||||
|
s.pages.pin(.{ .active = .{ .x = 0, .y = 1 } }).?,
|
||||||
|
s.pages.pin(.{ .active = .{ .x = s.pages.cols - 1, .y = 1 } }).?,
|
||||||
|
false,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Scroll down, should still be bottom
|
||||||
|
try s.cursorDownScroll();
|
||||||
|
|
||||||
|
// Our selection should've moved up
|
||||||
|
{
|
||||||
|
const sel = s.selection.?;
|
||||||
|
try testing.expectEqual(point.Point{ .active = .{
|
||||||
|
.x = 0,
|
||||||
|
.y = 0,
|
||||||
|
} }, s.pages.pointFromPin(.active, sel.start()).?);
|
||||||
|
try testing.expectEqual(point.Point{ .active = .{
|
||||||
|
.x = s.pages.cols - 1,
|
||||||
|
.y = 0,
|
||||||
|
} }, s.pages.pointFromPin(.active, sel.end()).?);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("2EFGH\n3IJKL", contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scrolling to the bottom does nothing
|
||||||
|
s.scroll(.{ .active = {} });
|
||||||
|
|
||||||
|
// Our selection should've stayed the same
|
||||||
|
{
|
||||||
|
const sel = s.selection.?;
|
||||||
|
try testing.expectEqual(point.Point{ .active = .{
|
||||||
|
.x = 0,
|
||||||
|
.y = 0,
|
||||||
|
} }, s.pages.pointFromPin(.active, sel.start()).?);
|
||||||
|
try testing.expectEqual(point.Point{ .active = .{
|
||||||
|
.x = s.pages.cols - 1,
|
||||||
|
.y = 0,
|
||||||
|
} }, s.pages.pointFromPin(.active, sel.end()).?);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("2EFGH\n3IJKL", contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll up again
|
||||||
|
try s.cursorDownScroll();
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("3IJKL", contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Our selection should be null because it left the screen.
|
||||||
|
{
|
||||||
|
const sel = s.selection.?;
|
||||||
|
try testing.expect(s.pages.pointFromPin(.active, sel.start()) == null);
|
||||||
|
try testing.expect(s.pages.pointFromPin(.active, sel.end()) == null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Screen: scroll and clear full screen" {
|
test "Screen: scroll and clear full screen" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
Reference in New Issue
Block a user