From fdd519f73b74371fcfed46457eeab3006d4b5b15 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 29 Dec 2023 12:34:33 -0800 Subject: [PATCH] terminal: cursor back should not reduce by one with pending wrap Fixes #1183 I'm not sure why the original logic was there. When I translated the original test cases to shell and ran them in xterm, they did NOT match what Ghostty expected. This updates the tests to match xterm and removes this case. We can add back in more tests if/when we figure out under what scenario this original logic was correct (if it ever was). --- src/terminal/Terminal.zig | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 2f08e07a0..f21970424 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1564,12 +1564,10 @@ pub fn cursorLeft(self: *Terminal, count_req: usize) void { break :wrap_mode .none; }; - // If we have a pending wrap state on, we reset it and reduce our count. + // Unset the pending wrap state no matter what + self.screen.cursor.pending_wrap = false; + var count: usize = @max(count_req, 1); - if (self.screen.cursor.pending_wrap) { - self.screen.cursor.pending_wrap = false; - count -= 1; - } // If we are in no wrap mode, then we move the cursor left and exit // since this is the fastest and most typical path. @@ -6245,7 +6243,7 @@ test "Terminal: cursorLeft unsets pending wrap state" { { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); - try testing.expectEqualStrings("ABCDX", str); + try testing.expectEqualStrings("ABCXE", str); } } @@ -6263,7 +6261,7 @@ test "Terminal: cursorLeft unsets pending wrap state with longer jump" { { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); - try testing.expectEqualStrings("ABXDE", str); + try testing.expectEqualStrings("AXCDE", str); } }