From 68bc11d2ce214de8c876be9d3859d7358c4201df Mon Sep 17 00:00:00 2001 From: rudolf-blue Date: Thu, 8 Oct 2026 14:46:56 -0400 Subject: [PATCH] Fix continued line detection once scrollback has wrapped around --- kitty/history.c | 4 ++-- kitty_tests/datatypes.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kitty/history.c b/kitty/history.c index 5224c28a5..488d41cf6 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -186,7 +186,7 @@ index_of(HistoryBuf *self, index_type lnum) { static bool hb_line_is_continued(HistoryBuf *self, index_type num) { - if (num == 0) { + if (num == self->start_of_data) { size_t sz; if (self->pagerhist && self->pagerhist->ringbuf && (sz = ringbuf_bytes_used(self->pagerhist->ringbuf)) > 0) { size_t pos = ringbuf_findchr(self->pagerhist->ringbuf, '\n', sz - 1); @@ -194,7 +194,7 @@ hb_line_is_continued(HistoryBuf *self, index_type num) { } return false; } - return cpu_lineptr(self, num - 1)[self->xnum - 1].next_char_was_wrapped; + return cpu_lineptr(self, (num + self->ynum - 1) % self->ynum)[self->xnum - 1].next_char_was_wrapped; } static void diff --git a/kitty_tests/datatypes.py b/kitty_tests/datatypes.py index 73c7479e7..44631f2f8 100644 --- a/kitty_tests/datatypes.py +++ b/kitty_tests/datatypes.py @@ -820,6 +820,14 @@ class TestDataTypes(BaseTest): self.assertEqual(p.wait(timeout=30), 0) p.stdout.close() + def test_historybuf_continued_after_wraparound(self): + s = self.create_screen(cols=5, lines=2, scrollback=4) + for i in range(7): + s.draw(str(i) * 7) + s.carriage_return(), s.linefeed() + hb = s.historybuf + self.ae([hb.is_continued(y) for y in range(hb.count)], [True, False, True, False]) + def test_historybuf(self): lb = filled_line_buf() hb = HistoryBuf(5, 5)