From cf3662442feebfbe331b2dd9fc1fafde0f103a9d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Apr 2021 16:56:53 +0530 Subject: [PATCH] Fix #3460 --- kitty/line-buf.c | 9 --------- kitty/lineops.h | 1 - kitty/screen.c | 12 ++++-------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/kitty/line-buf.c b/kitty/line-buf.c index beaf4ceda..f0d18156a 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -326,15 +326,6 @@ is_continued(LineBuf *self, PyObject *val) { Py_RETURN_FALSE; } -unsigned int -linebuf_continued_lines_count(const LineBuf *self, const index_type stop_before_line) { - index_type count = 0; - for (index_type i = 0; i < self->ynum && i < stop_before_line; i++) { - if (self->line_attrs[i] & CONTINUED_MASK) count++; - } - return count; -} - void linebuf_insert_lines(LineBuf *self, unsigned int num, unsigned int y, unsigned int bottom) { index_type i; diff --git a/kitty/lineops.h b/kitty/lineops.h index 77bde43eb..50443121e 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -91,7 +91,6 @@ void linebuf_clear(LineBuf *, char_type ch); void linebuf_index(LineBuf* self, index_type top, index_type bottom); void linebuf_reverse_index(LineBuf *self, index_type top, index_type bottom); void linebuf_clear_line(LineBuf *self, index_type y); -unsigned int linebuf_continued_lines_count(const LineBuf *, const index_type); void linebuf_insert_lines(LineBuf *self, unsigned int num, unsigned int y, unsigned int bottom); void linebuf_delete_lines(LineBuf *self, index_type num, index_type y, index_type bottom); void linebuf_copy_line_to(LineBuf *, Line *, index_type); diff --git a/kitty/screen.c b/kitty/screen.c index 9431451a8..4a6118e1d 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -273,6 +273,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { index_type num_content_lines_before, num_content_lines_after, num_content_lines; unsigned int cursor_x = 0, cursor_y = 0; bool cursor_is_beyond_content = false; + unsigned int lines_after_cursor_before_resize = self->lines - self->cursor->y; #define setup_cursor() { \ cursor_x = x; cursor_y = y; \ cursor_is_beyond_content = num_content_lines_before > 0 && self->cursor->y >= num_content_lines_before; \ @@ -290,10 +291,6 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { if (n == NULL) return false; - int lines_to_fill = -1; - if (is_main && OPT(scrollback_fill_enlarged_window)) { - lines_to_fill = (lines - self->main_linebuf->ynum) + linebuf_continued_lines_count(self->main_linebuf, self->cursor->y + 1); - } Py_CLEAR(self->main_linebuf); self->main_linebuf = n; if (is_main) setup_cursor(); grman_resize(self->main_grman, self->lines, lines, self->columns, columns); @@ -329,14 +326,13 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { self->cursor->y = num_content_lines; if (self->cursor->y >= self->lines) { self->cursor->y = self->lines - 1; screen_index(self); } } - if (lines_to_fill > 0) { - lines_to_fill -= linebuf_continued_lines_count(self->main_linebuf, self->cursor->y + 1); + if (is_main && OPT(scrollback_fill_enlarged_window)) { const unsigned int top = 0, bottom = self->lines-1; - while (lines_to_fill-- > 0) { + while (self->cursor->y + 1 < self->lines && self->lines - self->cursor->y > lines_after_cursor_before_resize) { if (!historybuf_pop_line(self->historybuf, self->alt_linebuf->line)) break; INDEX_DOWN; linebuf_copy_line_to(self->main_linebuf, self->alt_linebuf->line, 0); - if (self->cursor->y + 1 < self->lines) self->cursor->y++; + self->cursor->y++; } } return true;