From 8f44e16b898b43a8b2959f9814f32d3fd01d70e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 18 Feb 2025 19:37:44 +0530 Subject: [PATCH] Fix scroll_to_prompt after resize that causes prompt line wrapping not accurate See #8334 --- kitty/history.c | 4 +++- kitty_tests/screen.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kitty/history.c b/kitty/history.c index fbe9e93ca..829637ed4 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -638,7 +638,9 @@ historybuf_next_dest_line(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *src_line history_buf_set_last_char_as_continuation(self, 0, continued); bool needs_clear; index_type idx = historybuf_push(self, as_ansi_buf, &needs_clear); - *attrptr(self, idx) = src_line->attrs; + LineAttrs *a = attrptr(self, idx); + *a = src_line->attrs; + if (continued) a->prompt_kind = UNKNOWN_PROMPT_KIND; init_line(self, idx, dest_line); if (needs_clear) { zero_at_ptr_count(dest_line->cpu_cells, dest_line->xnum); diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 4111baa11..a8dbd16f7 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -1258,6 +1258,20 @@ class TestScreen(BaseTest): s.scroll_to_prompt(1) self.ae(lvco(), '0x\n1x') + # test that post rewrap prompt lines have correct attributes + s = self.create_screen(cols=5, lines=5, scrollback=15) + draw_prompt('P' * (s.columns - 2)) + draw_output(s.lines + 1, 'a') # ensure prompt is in scrollback + draw_prompt('Q' * (s.columns - 2)) + self.ae(str(s.visual_line(0)), '3a') + s.scroll_to_prompt() + self.ae(str(s.visual_line(0)), '$ PPP') + s.scroll_to_prompt(1) + self.ae(str(s.visual_line(0)), '3a') + s.resize(s.lines, s.columns - 2) + s.scroll_to_prompt() + self.ae(str(s.visual_line(0)), '$ P') + # last command output without line break s = self.create_screen(cols=10, lines=3) draw_prompt('p1')