diff --git a/kitty/data-types.h b/kitty/data-types.h index 86ea41e05..6c0015a89 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -321,6 +321,7 @@ void linebuf_set_attribute(LineBuf *, unsigned int , unsigned int ); void linebuf_rewrap(LineBuf *self, LineBuf *other, int *cursor_y_out, HistoryBuf *); bool historybuf_resize(HistoryBuf *self, index_type lines); void historybuf_add_line(HistoryBuf *self, const Line *line); +void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other); void screen_restore_cursor(Screen *); void screen_save_cursor(Screen *); diff --git a/kitty/screen.c b/kitty/screen.c index ee602f775..fc214dd33 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -63,6 +63,12 @@ void screen_reset(Screen *self) { screen_change_default_color(self, BG, 0); tracker_update_screen(self->change_tracker); } +static inline HistoryBuf* realloc_hb(HistoryBuf *old, unsigned int lines, unsigned int columns) { + HistoryBuf *ans = alloc_historybuf(lines, columns); + if (ans == NULL) { PyErr_NoMemory(); return NULL; } + historybuf_rewrap(old, ans); + return ans; +} static inline LineBuf* realloc_lb(LineBuf *old, unsigned int lines, unsigned int columns, int *cursor_y, HistoryBuf *hb) { LineBuf *ans = alloc_linebuf(lines, columns); @@ -76,6 +82,9 @@ static bool screen_resize(Screen *self, unsigned int lines, unsigned int columns bool is_main = self->linebuf == self->main_linebuf; int cursor_y = -1; + HistoryBuf *nh = realloc_hb(self->historybuf, lines, columns); + if (nh == NULL) return false; + Py_CLEAR(self->historybuf); self->historybuf = nh; LineBuf *n = realloc_lb(self->main_linebuf, lines, columns, &cursor_y, self->historybuf); if (n == NULL) return false; Py_CLEAR(self->main_linebuf); self->main_linebuf = n;