Skip to content

Commit

Permalink
Fix continuation char marking when rewrapping historybuf
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Dec 28, 2024
1 parent 79c3add commit 717c564
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
16 changes: 8 additions & 8 deletions kitty/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,6 @@ historybuf_pop_line(HistoryBuf *self, Line *line) {
return true;
}

static void
history_buf_set_last_char_as_continuation(HistoryBuf *self, index_type y, bool wrapped) {
if (self->count > 0) {
cpu_lineptr(self, index_of(self, y))[self->xnum-1].next_char_was_wrapped = wrapped;
}
}

static PyObject*
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"
Expand Down Expand Up @@ -608,9 +601,16 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns, unsigned
}
// }}}

static void
history_buf_set_last_char_as_continuation(HistoryBuf *self, index_type y, bool wrapped) {
if (self->count > 0) {
cpu_lineptr(self, index_of(self, y))[self->xnum-1].next_char_was_wrapped = wrapped;
}
}

index_type
historybuf_next_dest_line(HistoryBuf *self, ANSIBuf *as_ansi_buf, Line *src_line, index_type dest_y, Line *dest_line, bool continued) {
history_buf_set_last_char_as_continuation(self, dest_y, continued);
history_buf_set_last_char_as_continuation(self, 0, continued);
index_type idx = historybuf_push(self, as_ansi_buf);
*attrptr(self, idx) = src_line->attrs;
init_line(self, idx, dest_line);
Expand Down
7 changes: 7 additions & 0 deletions kitty/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,12 @@ last_char_has_wrapped_flag(Line* self, PyObject *a UNUSED) {
Py_RETURN_FALSE;
}

static PyObject*
set_wrapped_flag(Line* self, PyObject *is_wrapped) {
self->cpu_cells[self->xnum-1].next_char_was_wrapped = PyObject_IsTrue(is_wrapped);
Py_RETURN_NONE;
}

static PyObject*
__repr__(Line* self) {
PyObject *s = line_as_unicode(self, false);
Expand Down Expand Up @@ -1028,6 +1034,7 @@ static PyMethodDef methods[] = {
METHOD(set_attribute, METH_VARARGS)
METHOD(as_ansi, METH_NOARGS)
METHOD(last_char_has_wrapped_flag, METH_NOARGS)
METHODB(set_wrapped_flag, METH_O),
METHOD(hyperlink_ids, METH_NOARGS)
METHOD(width, METH_O)
METHOD(url_start_at, METH_O)
Expand Down
12 changes: 12 additions & 0 deletions kitty_tests/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,18 @@ def test_historybuf(self):
self.ae(str(hb.line(i)).rstrip(), str(3000 - 1 - i))

# rewrap
def as_ansi(hb):
lines = []
hb.as_ansi(lines.append)
return ''.join(lines)
hb = filled_history_buf(5, 5)
for i in range(hb.ynum):
hb.line(i).set_wrapped_flag(True)
hb2 = HistoryBuf(3, 10)
before = as_ansi(hb)
hb.rewrap(hb2)
self.ae(before, as_ansi(hb2).rstrip())

hb = filled_history_buf(5, 5)
hb2 = HistoryBuf(hb.ynum, hb.xnum)
hb.rewrap(hb2)
Expand Down

0 comments on commit 717c564

Please sign in to comment.