From 79c07862eaab0452f6109bff58f3405b5a436627 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 22 Jan 2025 14:19:45 +0530 Subject: [PATCH] Fix history buffer not clearing lines when rewrapping and the number of lines is larger than size of buffer --- kitty/history.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kitty/history.c b/kitty/history.c index d484cab731..770f628af8 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -286,18 +286,23 @@ pagerhist_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) { } static index_type -historybuf_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) { +historybuf_push(HistoryBuf *self, ANSIBuf *as_ansi_buf, bool *needs_clear) { index_type idx = (self->start_of_data + self->count) % self->ynum; if (self->count == self->ynum) { pagerhist_push(self, as_ansi_buf); self->start_of_data = (self->start_of_data + 1) % self->ynum; - } else self->count++; + *needs_clear = true; + } else { + self->count++; + *needs_clear = false; + } return idx; } void historybuf_add_line(HistoryBuf *self, const Line *line, ANSIBuf *as_ansi_buf) { - index_type idx = historybuf_push(self, as_ansi_buf); + bool needs_clear; + index_type idx = historybuf_push(self, as_ansi_buf, &needs_clear); init_line(self, idx, self->line); copy_line(line, self->line); *attrptr(self, idx) = line->attrs; @@ -621,9 +626,14 @@ history_buf_set_last_char_as_continuation(HistoryBuf *self, index_type y, bool w index_type historybuf_next_dest_line(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *src_line, index_type dest_y, Line *dest_line, bool continued) { history_buf_set_last_char_as_continuation(self, 0, continued); - index_type idx = historybuf_push(self, as_ansi_buf); + bool needs_clear; + index_type idx = historybuf_push(self, as_ansi_buf, &needs_clear); *attrptr(self, idx) = src_line->attrs; init_line(self, idx, dest_line); + if (needs_clear) { + zero_at_ptr_count(dest_line->cpu_cells, dest_line->xnum); + zero_at_ptr_count(dest_line->gpu_cells, dest_line->xnum); + } return dest_y + 1; }