Fix scroll_to_prompt after resize that causes prompt line wrapping not accurate

See #8334
This commit is contained in:
Kovid Goyal 2025-02-18 19:37:44 +05:30
parent f29bc638ce
commit 8f44e16b89
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 17 additions and 1 deletions

View file

@ -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);

View file

@ -1258,6 +1258,20 @@ def lvco():
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')