Fix incorrect handling of trailing whitespace for lines in the history buffer when resizing

This commit is contained in:
Kovid Goyal 2016-12-11 14:48:00 +05:30
parent 431322a263
commit b6c639c487
2 changed files with 18 additions and 7 deletions

View File

@ -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);

View File

@ -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()