From a7fce9353ad753a9914ec96fb2148603c8c74661 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 10 Dec 2016 14:18:27 +0530 Subject: [PATCH] Fix an off-by-one error when scrolling back --- kitty/char_grid.py | 8 ++++---- kitty/history.c | 2 +- kitty/screen.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kitty/char_grid.py b/kitty/char_grid.py index 5bc44db2f..9120e9228 100644 --- a/kitty/char_grid.py +++ b/kitty/char_grid.py @@ -183,7 +183,7 @@ class Selection: # {{{ def line(y): if y < 0: - return historybuf.line(-y) + return historybuf.line(-1 - y) return linebuf.line(y) lines = [] @@ -286,7 +286,7 @@ class CharGrid: amt = {'line': 1, 'page': self.screen.lines - 1, 'full': self.screen.historybuf.count}[amt] if not upwards: amt *= -1 - y = max(0, min(self.scrolled_by + amt, self.screen.historybuf.count - 1)) + y = max(0, min(self.scrolled_by + amt, self.screen.historybuf.count)) if y != self.scrolled_by: self.scrolled_by = y self.update_cell_data() @@ -298,7 +298,7 @@ class CharGrid: cursor_changed, history_line_added_count = self.screen.update_cell_data( sprites.backend, self.color_profile, addressof(self.main_sprite_map), self.default_fg, self.default_bg, force_full_refresh) if self.scrolled_by: - self.scrolled_by = min(self.scrolled_by + history_line_added_count, self.screen.historybuf.count - 1) + self.scrolled_by = min(self.scrolled_by + history_line_added_count, self.screen.historybuf.count) self.screen.set_scroll_cell_data( sprites.backend, self.color_profile, addressof(self.main_sprite_map), self.default_fg, self.default_bg, self.scrolled_by, addressof(self.scroll_sprite_map)) @@ -370,7 +370,7 @@ class CharGrid: if y >= 0 and y < self.screen.lines: if self.scrolled_by: if y < self.scrolled_by: - return self.screen.historybuf.line(self.scrolled_by - y) + return self.screen.historybuf.line(self.scrolled_by - 1 - y) return self.screen.line(y - self.scrolled_by) else: return self.screen.line(y) diff --git a/kitty/history.c b/kitty/history.c index 000570305..3af7f66de 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -130,7 +130,7 @@ line(HistoryBuf *self, PyObject *val) { #define line_doc "Return the line with line number val. This buffer grows upwards, i.e. 0 is the most recently added line" if (self->count == 0) { PyErr_SetString(PyExc_IndexError, "This buffer is empty"); return NULL; } index_type lnum = PyLong_AsUnsignedLong(val); - if (lnum > self->count - 1) { PyErr_SetString(PyExc_IndexError, "Out of bounds"); return NULL; } + if (lnum >= self->count) { PyErr_SetString(PyExc_IndexError, "Out of bounds"); return NULL; } init_line(self, index_of(self, lnum), self->line); Py_INCREF(self->line); return (PyObject*)self->line; diff --git a/kitty/screen.c b/kitty/screen.c index 82b2d565b..ec8144a1c 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1080,7 +1080,7 @@ set_scroll_cell_data(Screen *self, PyObject *args) { scrolled_by = MIN(self->historybuf->count, scrolled_by); for (index_type y = 0; y < MIN(self->lines, scrolled_by); y++) { - historybuf_init_line(self->historybuf, scrolled_by - y, self->historybuf->line); + historybuf_init_line(self->historybuf, scrolled_by - 1 - y, self->historybuf->line); self->historybuf->line->ynum = y; if (!update_cell_range_data(&(self->modes), spm, self->historybuf->line, 0, self->columns - 1, color_profile, default_bg, default_fg, data)) return NULL; }