From cf2fffaf95f4dcf8ff9b21872de41c115054155c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 28 Dec 2024 10:48:21 +0530 Subject: [PATCH] Fix continuation char marking when rewrapping historybuf --- kitty/history.c | 16 ++++++++-------- kitty/line.c | 7 +++++++ kitty_tests/datatypes.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/kitty/history.c b/kitty/history.c index dbbcbea5f..e98df12b1 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -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" @@ -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); diff --git a/kitty/line.c b/kitty/line.c index a6916b5a6..e380fc49e 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -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); @@ -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) diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index df4ad22e7..1ff997a0d 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -486,6 +486,18 @@ class TestDataTypes(BaseTest): 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)