mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
terminal: Screen scroll test and handle single row screens
This commit is contained in:
@ -484,24 +484,29 @@ pub fn cursorDownScroll(self: *Screen) !void {
|
|||||||
|
|
||||||
// If we have no scrollback, then we shift all our rows instead.
|
// If we have no scrollback, then we shift all our rows instead.
|
||||||
if (self.no_scrollback) {
|
if (self.no_scrollback) {
|
||||||
// Erase rows will shift our rows up
|
// If we have a single-row screen, we have no rows to shift
|
||||||
self.pages.eraseRows(.{ .active = .{} }, .{ .active = .{} });
|
// so our cursor is in the correct place we just have to clear
|
||||||
|
// the cells.
|
||||||
|
if (self.pages.rows > 1) {
|
||||||
|
// Erase rows will shift our rows up
|
||||||
|
self.pages.eraseRows(.{ .active = .{} }, .{ .active = .{} });
|
||||||
|
|
||||||
// We need to move our cursor down one because eraseRows will
|
// We need to move our cursor down one because eraseRows will
|
||||||
// preserve our pin directly and we're erasing one row.
|
// preserve our pin directly and we're erasing one row.
|
||||||
const page_pin = self.cursor.page_pin.down(1).?;
|
const page_pin = self.cursor.page_pin.down(1).?;
|
||||||
self.cursorChangePin(page_pin);
|
self.cursorChangePin(page_pin);
|
||||||
const page_rac = page_pin.rowAndCell();
|
const page_rac = page_pin.rowAndCell();
|
||||||
self.cursor.page_row = page_rac.row;
|
self.cursor.page_row = page_rac.row;
|
||||||
self.cursor.page_cell = page_rac.cell;
|
self.cursor.page_cell = page_rac.cell;
|
||||||
|
}
|
||||||
|
|
||||||
// Erase rows does NOT clear the cells because in all other cases
|
// Erase rows does NOT clear the cells because in all other cases
|
||||||
// we never write those rows again. Active erasing is a bit
|
// we never write those rows again. Active erasing is a bit
|
||||||
// different so we manually clear our one row.
|
// different so we manually clear our one row.
|
||||||
self.clearCells(
|
self.clearCells(
|
||||||
&page_pin.page.data,
|
&self.cursor.page_pin.page.data,
|
||||||
self.cursor.page_row,
|
self.cursor.page_row,
|
||||||
page_pin.page.data.getCells(self.cursor.page_row),
|
self.cursor.page_pin.page.data.getCells(self.cursor.page_row),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const old_pin = self.cursor.page_pin.*;
|
const old_pin = self.cursor.page_pin.*;
|
||||||
@ -2709,6 +2714,47 @@ test "Screen: scrolling" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Screen: scrolling with a single-row screen no scrollback" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 10, 1, 0);
|
||||||
|
defer s.deinit();
|
||||||
|
try s.testWriteString("1ABCD");
|
||||||
|
|
||||||
|
// Scroll down, should still be bottom
|
||||||
|
try s.cursorDownScroll();
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Screen: scrolling with a single-row screen with scrollback" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 10, 1, 1);
|
||||||
|
defer s.deinit();
|
||||||
|
try s.testWriteString("1ABCD");
|
||||||
|
|
||||||
|
// Scroll down, should still be bottom
|
||||||
|
try s.cursorDownScroll();
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("", contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
s.scroll(.{ .delta_row = -1 });
|
||||||
|
{
|
||||||
|
const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} });
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("1ABCD", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Screen: scrolling across pages preserves style" {
|
test "Screen: scrolling across pages preserves style" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
Reference in New Issue
Block a user