From 96d5ca3604d16e482f00ae6038e0ea44a37700d8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Oct 2023 08:45:07 -0700 Subject: [PATCH] terminal: horizontal tab back should handle cursor already left margin --- src/terminal/Terminal.zig | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 86eaf119f..16e12deae 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1541,7 +1541,7 @@ pub fn horizontalTabBack(self: *Terminal) !void { while (true) { // 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 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" { const alloc = testing.allocator; var t = try init(alloc, 5, 5);