Skip to content

Commit

Permalink
Fix history buffer not clearing lines when rewrapping and the number …
Browse files Browse the repository at this point in the history
…of lines is larger than size of buffer
  • Loading branch information
kovidgoyal committed Jan 22, 2025
1 parent e5c76f1 commit 79c0786
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions kitty/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 79c0786

Please sign in to comment.