diff --git a/docs/changelog.rst b/docs/changelog.rst index 62138830a..f1d94e467 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -231,6 +231,8 @@ Detailed list of changes 0.50.0 [future] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Fix cursor position reports returning the wrong row in origin mode + - 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 a key in the keychain, when logging out, restarting or shutting down the diff --git a/kitty/screen.c b/kitty/screen.c index c24d64293..17c035966 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -3284,7 +3284,7 @@ report_device_status(Screen *self, unsigned int which, bool private) { y++; } else x--; } - if (self->modes.mDECOM) y -= MAX(y, self->margin_top); + if (self->modes.mDECOM) y -= MIN(y, self->margin_top); // 1-based indexing int sz = snprintf(buf, sizeof(buf) - 1, "%s%u;%uR", (private ? "?" : ""), y + 1, x + 1); if (sz > 0) write_escape_code_to_child(self, ESC_CSI, buf); diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index af8e6dc61..1d2caf474 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -1013,6 +1013,19 @@ 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.