From c0b384f310cd20f83237fe1e55b2d57ba62ac550 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Oct 2026 07:58:49 +0530 Subject: [PATCH] Cleanup previous PR --- docs/changelog.rst | 2 +- kitty/screen.c | 3 ++- kitty_tests/parser.py | 13 ------------- kitty_tests/screen.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f1d94e467..74944073c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -231,7 +231,7 @@ Detailed list of changes 0.50.0 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Fix cursor position reports returning the wrong row in origin mode +- Fix cursor position reports returning the wrong row in origin mode (:pull:`10682`) - macOS: A new option :opt:`restore_session_after_logout` to save the state of every kitty instance, including the scrollback of every window, encrypted with diff --git a/kitty/screen.c b/kitty/screen.c index 17c035966..7a7dce8de 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -3279,7 +3279,8 @@ report_device_status(Screen *self, unsigned int which, bool private) { x = self->cursor->x; y = self->cursor->y; if (x >= self->columns) { - if (y < self->lines - 1) { + // A wrap at the bottom margin scrolls the region, leaving the cursor on the same row + if (y < self->lines - 1 && y != self->margin_bottom) { x = 0; y++; } else x--; diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index 1d2caf474..af8e6dc61 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -1013,19 +1013,6 @@ class TestParser(BaseTest): self.ae(c.wtcbuf, b'\x1b[?2033;1$y') pb('\033[?2033l', ('screen_reset_mode', 2033, 1)) - def test_cursor_position_report_origin_mode(self) -> None: - s = self.create_screen(cols=10, lines=10) - for top in (1, 3): - for origin in (False, True): - parse_bytes(s, f'\033[{top};8r\033[?6{"h" if origin else "l"}'.encode()) - for row in (1, 4): - parse_bytes(s, f'\033[{row};5H'.encode()) - for private in ('', '?'): - with self.subTest(top=top, origin=origin, row=row, private=private): - s.callbacks.clear() - parse_bytes(s, f'\033[{private}6n'.encode()) - self.ae(s.callbacks.wtcbuf, f'\033[{private}{row};5R'.encode()) - def test_malformed_csi_subparam_does_not_corrupt_sgr(self): # Regression for #10434: \e[?:m sets is_sub_param[0]=true in the CSI # state. reset_csi must clear that flag so the next SGR isn't rejected. diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 1a00d601b..a050c06dd 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -647,6 +647,35 @@ class TestScreen(BaseTest): parse_bytes(s, b'\x1b[?2033l\x1b[?2033$p') # ]] self.ae(c.wtcbuf, b'\x1b[?2033;2$y') # ] + def test_cursor_position_report_origin_mode(self): + s = self.create_screen(cols=10, lines=10) + + def report(private=''): + s.callbacks.clear() + parse_bytes(s, f'\x1b[{private}6n'.encode()) # ] + return s.callbacks.wtcbuf.decode() + + for top in (1, 3): + for origin in (False, True): + parse_bytes(s, f'\x1b[{top};8r\x1b[?6{"h" if origin else "l"}'.encode()) # ]] + for row in (1, 4): + parse_bytes(s, f'\x1b[{row};5H'.encode()) # ] + for private in ('', '?'): + with self.subTest(top=top, origin=origin, row=row, private=private): + self.ae(report(private), f'\x1b[{private}{row};5R') # ] + # cursor addressing is clamped to the bottom margin in origin mode + parse_bytes(s, b'\x1b[3;8r\x1b[?6h\x1b[99;5H') # ]]] + self.ae(report(), '\x1b[6;5R') # ] + # pending wrap at the bottom margin stays on the same row + parse_bytes(s, b'\x1b[6;10Hx') # ] + self.ae(report(), '\x1b[6;10R') # ] + # pending wrap inside the region moves to the start of the next row + parse_bytes(s, b'\x1b[2;10Hx') # ] + self.ae(report(), '\x1b[3;1R') # ] + # pending wrap at the bottom of the screen outside the region + parse_bytes(s, b'\x1b[?6l\x1b[10;10Hx') # ]] + self.ae(report(), '\x1b[10;10R') # ] + def test_da1(self): s = self.create_screen() parse_bytes(s, b'\x1b[c\x1b[0c') # ]]