terminal: insert blanks (ICH) with left/right and large count

This commit is contained in:
Mitchell Hashimoto
2023-10-24 09:38:47 -07:00
parent e6a23be99a
commit ec26cc4b41

View File

@ -1655,7 +1655,7 @@ pub fn insertBlanks(self: *Terminal, count: usize) void {
// Determine our indexes. // Determine our indexes.
const start = self.screen.cursor.x; const start = self.screen.cursor.x;
const pivot = self.screen.cursor.x + count; const pivot = @min(self.screen.cursor.x + count, right_limit);
// This is the number of spaces we have left to shift existing data. // This is the number of spaces we have left to shift existing data.
// If count is bigger than the available space left after the cursor, // If count is bigger than the available space left after the cursor,
@ -4289,6 +4289,25 @@ test "Terminal: insertBlanks outside left/right scroll region" {
} }
} }
test "Terminal: insertBlanks left/right scroll region large count" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 10);
defer t.deinit(alloc);
t.modes.set(.origin, true);
t.modes.set(.enable_left_and_right_margin, true);
t.setLeftAndRightMargin(3, 5);
t.setCursorPos(1, 1);
t.insertBlanks(140);
try t.print('X');
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings(" X", str);
}
}
test "Terminal: insert mode with space" { test "Terminal: insert mode with space" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 2); var t = try init(alloc, 10, 2);