mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #1036 from mitchellh/resize
terminal: resize to less rows with empty lines should trim lines
This commit is contained in:
@ -2485,11 +2485,14 @@ pub fn resizeWithoutReflow(self: *Screen, rows: usize, cols: usize) !void {
|
||||
// because we aren't going to trim.
|
||||
if (self.rows == rows) break :blank 0;
|
||||
|
||||
// If there is history, blank line counting is disabled and
|
||||
// we generate scrollback. Why? Terminal.app does it, seems... fine.
|
||||
if (self.history > 0) break :blank 0;
|
||||
const blank = self.trailingBlankLines();
|
||||
|
||||
break :blank self.trailingBlankLines();
|
||||
// If we are shrinking the number of rows, we don't want to trim
|
||||
// off more blank rows than the number we're shrinking because it
|
||||
// creates a jarring screen move experience.
|
||||
if (self.rows > rows) break :blank @min(blank, self.rows - rows);
|
||||
|
||||
break :blank blank;
|
||||
};
|
||||
|
||||
// Make a copy so we can access the old indexes.
|
||||
@ -5764,6 +5767,31 @@ test "Screen: resize (no reflow) less rows with scrollback" {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/mitchellh/ghostty/issues/1030
|
||||
test "Screen: resize (no reflow) less rows with empty trailing" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var s = try init(alloc, 3, 5, 5);
|
||||
defer s.deinit();
|
||||
const str = "1\n2\n3\n4\n5\n6\n7\n8";
|
||||
try s.testWriteString(str);
|
||||
try s.scroll(.{ .clear = {} });
|
||||
s.cursor.x = 0;
|
||||
s.cursor.y = 0;
|
||||
try s.testWriteString("A\nB");
|
||||
|
||||
const cursor = s.cursor;
|
||||
try s.resizeWithoutReflow(2, 5);
|
||||
try testing.expectEqual(cursor, s.cursor);
|
||||
|
||||
{
|
||||
const contents = try s.testString(alloc, .viewport);
|
||||
defer alloc.free(contents);
|
||||
try testing.expectEqualStrings("A\nB", contents);
|
||||
}
|
||||
}
|
||||
|
||||
test "Screen: resize (no reflow) empty screen" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
Reference in New Issue
Block a user