terminal: insertBlanks doesn't split spacer tail

This commit is contained in:
Mitchell Hashimoto
2024-03-24 21:27:45 -07:00
parent db3ab4b0c8
commit 3e84591b84

View File

@ -1559,6 +1559,13 @@ pub fn insertBlanks(self: *Terminal, count: usize) void {
const left: [*]Cell = @ptrCast(self.screen.cursor.page_cell); const left: [*]Cell = @ptrCast(self.screen.cursor.page_cell);
var page = &self.screen.cursor.page_pin.page.data; var page = &self.screen.cursor.page_pin.page.data;
// If our X is a wide spacer tail then we need to erase the
// previous cell too so we don't split a multi-cell character.
if (self.screen.cursor.page_cell.wide == .spacer_tail) {
assert(self.screen.cursor.x > 0);
self.screen.clearCells(page, self.screen.cursor.page_row, (left - 1)[0..2]);
}
// Remaining cols from our cursor to the right margin. // Remaining cols from our cursor to the right margin.
const rem = self.scrolling_region.right - self.screen.cursor.x + 1; const rem = self.scrolling_region.right - self.screen.cursor.x + 1;
@ -6434,6 +6441,22 @@ test "Terminal: insertBlanks shift graphemes" {
try testing.expectEqual(@as(usize, 1), page.graphemeCount()); try testing.expectEqual(@as(usize, 1), page.graphemeCount());
} }
test "Terminal: insertBlanks split multi-cell character from tail" {
const alloc = testing.allocator;
var t = try init(alloc, .{ .cols = 5, .rows = 10 });
defer t.deinit(alloc);
try t.printString("橋123");
t.setCursorPos(1, 2);
t.insertBlanks(1);
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings(" 12", 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, .{ .cols = 10, .rows = 2 }); var t = try init(alloc, .{ .cols = 10, .rows = 2 });