From a0aba4da4a338585c4e6f3d1abba9d53a1efafd4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 23 Mar 2024 08:43:06 +0530 Subject: [PATCH] Fix handling of tab character when cursor is at end of line and wrapping is enabled Fixes #7250 --- docs/changelog.rst | 2 ++ kitty/screen.c | 13 ++++++++++++- kitty_tests/screen.py | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 73647913a..5f224a357 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -62,6 +62,8 @@ Detailed list of changes - macOS: Fix a regression in the previous release that broke rendering of some symbols on some systems (:iss:`7249`) +- Fix handling of tab character when cursor is at end of line and wrapping is enabled (:iss:`7250`) + 0.33.1 [2024-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/screen.c b/kitty/screen.c index dbcb6447b..373a4573d 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -730,7 +730,18 @@ draw_text_loop(Screen *self, const uint32_t *chars, size_t num_chars, text_loop_ case BS: screen_backspace(self); break; case HT: - screen_tab(self); break; + if (UNLIKELY(self->cursor->x >= self->columns)) { + if (self->modes.mDECAWM) { + // xterm discards the TAB in this case so match its behavior + continue_to_next_line(self); + init_text_loop_line(self, s); + } else if (self->columns > 0){ + self->cursor->x = self->columns - 1; + if (cursor_on_wide_char_trailer(self, s)) move_cursor_off_wide_char_trailer(self, s); + screen_tab(self); + } + } else screen_tab(self); + break; case SI: screen_change_charset(self, 0); break; case SO: diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index e61920350..017ce6077 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -419,6 +419,9 @@ def test_tab_stops(self): s.draw('*') s.cursor_position(2, 2) self.ae(str(s.line(0)), '\t*'*13) + s = self.create_screen(cols=4, lines=2) + s.draw('aaaX\tbbbb') + self.ae(str(s.line(0)) + str(s.line(1)), 'aaaXbbbb') def test_margins(self): # Taken from vttest/main.c