From b6c639c48732a8823303f730f7a271f487217329 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 11 Dec 2016 14:48:00 +0530 Subject: [PATCH] Fix incorrect handling of trailing whitespace for lines in the history buffer when resizing --- kitty/history.c | 18 +++++++++++------- kitty_tests/datatypes.py | 7 +++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/kitty/history.c b/kitty/history.c index 3af7f66de..41efd7d45 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -10,6 +10,12 @@ #define CELL_SIZE_H (CELL_SIZE + 1) +static inline uint8_t* +start_of(HistoryBuf *self, index_type num) { + // Pointer to the start of the line with index (buffer position) num + return self->buf + CELL_SIZE_H * num * self->xnum; +} + static PyObject * new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { HistoryBuf *self; @@ -34,6 +40,10 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { Py_CLEAR(self); } else { self->line->xnum = xnum; + for(index_type y = 0; y < self->ynum; y++) { + self->line->chars = (char_type*)(start_of(self, y) + 1); + for (index_type i = 0; i < self->xnum; i++) self->line->chars[i] = (1 << ATTRS_SHIFT) | 32; + } } } @@ -56,12 +66,6 @@ index_of(HistoryBuf *self, index_type lnum) { return (self->start_of_data + idx) % self->ynum; } -static inline uint8_t* -start_of(HistoryBuf *self, index_type num) { - // Pointer to the start of the line with index (buffer position) num - return self->buf + CELL_SIZE_H * num * self->xnum; -} - static inline void init_line(HistoryBuf *self, index_type num, Line *l) { // Initialize the line l, setting its pointer to the offsets for the line at index (buffer position) num @@ -214,7 +218,7 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns) { #define is_src_line_continued(src_y) (map_src_index(src_y) < src->ynum - 1 ? *(start_of(src, map_src_index(src_y + 1))) : false) -#define next_dest_line(cont) historybuf_push(dest); dest->line->continued = cont; +#define next_dest_line(cont) *start_of(dest, historybuf_push(dest)) = cont; dest->line->continued = cont; #define first_dest_line next_dest_line(false); diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index 0730c2556..8e2c40101 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -321,6 +321,13 @@ class TestDataTypes(BaseTest): hb.rewrap(hb2) for i in range(hb2.ynum): self.ae(hb2.line(i), hb.line(i)) + hb = filled_history_buf(5, 5) + hb2 = HistoryBuf(hb.ynum, hb.xnum * 2) + hb.rewrap(hb2) + hb3 = HistoryBuf(hb.ynum, hb.xnum) + hb2.rewrap(hb3) + for i in range(hb.ynum): + self.ae(hb.line(i), hb3.line(i)) def test_ansi_repr(self): lb = filled_line_buf()