terminal: horizontal tab back should handle cursor already left margin

This commit is contained in:
Mitchell Hashimoto
2023-10-24 08:45:07 -07:00
parent cbdf52864a
commit 96d5ca3604

View File

@ -1541,7 +1541,7 @@ pub fn horizontalTabBack(self: *Terminal) !void {
while (true) { while (true) {
// If we're already at the edge of the screen, then we're done. // If we're already at the edge of the screen, then we're done.
if (self.screen.cursor.x == left_limit) return; if (self.screen.cursor.x <= left_limit) return;
// Move the cursor left // Move the cursor left
self.screen.cursor.x -= 1; self.screen.cursor.x -= 1;
@ -2733,6 +2733,26 @@ test "Terminal: horizontal tabs with left margin in origin mode" {
} }
} }
test "Terminal: horizontal tab back with cursor before left margin" {
const alloc = testing.allocator;
var t = try init(alloc, 20, 5);
defer t.deinit(alloc);
t.modes.set(.origin, true);
t.saveCursor();
t.modes.set(.enable_left_and_right_margin, true);
t.setLeftAndRightMargin(5, 0);
t.restoreCursor();
try t.horizontalTabBack();
try t.print('X');
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("X", str);
}
}
test "Terminal: cursorPos resets wrap" { test "Terminal: cursorPos resets wrap" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);