Merge pull request #84 from mitchellh/resize

Resize Fixes
This commit is contained in:
Mitchell Hashimoto
2023-03-02 13:53:20 -08:00
committed by GitHub
3 changed files with 48 additions and 6 deletions

View File

@ -119,8 +119,8 @@ pub const Config = struct {
/// the grid will be completely squished by the padding. It is up to you
/// as the user to pick a reasonable value. If you pick an unreasonable
/// value, a warning will appear in the logs.
@"window-padding-x": u32 = 0,
@"window-padding-y": u32 = 0,
@"window-padding-x": u32 = 2,
@"window-padding-y": u32 = 2,
/// The viewport dimensions are usually not perfectly divisible by
/// the cell size. In this case, some extra padding on the end of a
@ -134,7 +134,7 @@ pub const Config = struct {
/// still apply. The other padding is applied first and may affect how
/// many grid cells actually exist, and this is applied last in order
/// to balance the padding given a certain viewport size and grid cell size.
@"window-padding-balance": bool = true,
@"window-padding-balance": bool = false,
/// If true, new windows and tabs will inherit the font size of the previously
/// focused window. If no window was previously focused, the default

View File

@ -1985,12 +1985,12 @@ pub fn resize(self: *Screen, rows: usize, cols: usize) !void {
// We grow rows after cols so that we can do our unwrapping/reflow
// before we do a no-reflow grow.
if (rows > self.rows) try self.resizeWithoutReflow(rows, cols);
if (rows > self.rows) try self.resizeWithoutReflow(rows, self.cols);
// If our rows got smaller, we trim the scrollback. We do this after
// handling cols growing so that we can save as many lines as we can.
// We do it before cols shrinking so we can save compute on that operation.
if (rows < self.rows) try self.resizeWithoutReflow(rows, cols);
if (rows < self.rows) try self.resizeWithoutReflow(rows, self.cols);
// If our cols got smaller, we have to reflow text. This is the worst
// possible case because we can't do any easy tricks to get reflow,
@ -4905,6 +4905,44 @@ test "Screen: resize less cols with reflow previously wrapped and scrollback" {
try testing.expectEqual(@as(usize, 2), s.cursor.y);
}
test "Screen: resize more rows, less cols with reflow with scrollback" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 3, 5, 3);
defer s.deinit();
const str = "1ABCD\n2EFGH3IJKL\n4MNOP";
try s.testWriteString(str);
{
var contents = try s.testString(alloc, .screen);
defer alloc.free(contents);
const expected = "1ABCD\n2EFGH\n3IJKL\n4MNOP";
try testing.expectEqualStrings(expected, contents);
}
{
var contents = try s.testString(alloc, .viewport);
defer alloc.free(contents);
const expected = "2EFGH\n3IJKL\n4MNOP";
try testing.expectEqualStrings(expected, contents);
}
try s.resize(10, 2);
{
var contents = try s.testString(alloc, .viewport);
defer alloc.free(contents);
const expected = "BC\nD\n2E\nFG\nH3\nIJ\nKL\n4M\nNO\nP";
try testing.expectEqualStrings(expected, contents);
}
{
var contents = try s.testString(alloc, .screen);
defer alloc.free(contents);
const expected = "1A\nBC\nD\n2E\nFG\nH3\nIJ\nKL\n4M\nNO\nP";
try testing.expectEqualStrings(expected, contents);
}
}
// This seems like it should work fine but for some reason in practice
// in the initial implementation I found this bug! This is a regression
// test for that.

View File

@ -904,7 +904,11 @@ pub fn eraseDisplay(
switch (mode) {
.complete => {
var it = self.screen.rowIterator(.active);
while (it.next()) |row| row.clear(self.screen.cursor.pen);
while (it.next()) |row| {
row.setWrapped(false);
row.setDirty(true);
row.clear(self.screen.cursor.pen);
}
// Unsets pending wrap state
self.screen.cursor.pending_wrap = false;