diff --git a/docs/changelog.rst b/docs/changelog.rst index 32eb1e828..d8954492a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -46,6 +46,8 @@ Detailed list of changes - Wayland GNOME: Fix ghosting when using :opt:`background_tint` (:iss:`5605`) +- Fix cursor position at x=0 changing to x=1 on resize (:iss:`5635`) + 0.26.4 [2022-10-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/rewrap.h b/kitty/rewrap.h index 3c02adc93..a92fd34cd 100644 --- a/kitty/rewrap.h +++ b/kitty/rewrap.h @@ -81,7 +81,7 @@ rewrap_inner(BufType *src, BufType *dest, const index_type src_limit, HistoryBuf for (TrackCursor *t = track; !t->is_sentinel; t++) { if (t->is_tracked_line && src_x <= t->x && t->x < src_x + num) { t->y = dest_y; - t->x = dest_x + (t->x - src_x + 1); + t->x = dest_x + (t->x - src_x + (t->x > 0)); } } src_x += num; dest_x += num; diff --git a/kitty/screen.c b/kitty/screen.c index e52dd98ff..7b9102ff6 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -368,6 +368,7 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { if (n == NULL) return false; Py_CLEAR(self->main_linebuf); self->main_linebuf = n; if (is_main) setup_cursor(cursor); + /* printf("old_cursor: (%u, %u) new_cursor: (%u, %u) beyond_content: %d\n", self->cursor->x, self->cursor->y, cursor.after.x, cursor.after.y, cursor.is_beyond_content); */ setup_cursor(main_saved_cursor); grman_resize(self->main_grman, self->lines, lines, self->columns, columns); @@ -396,7 +397,6 @@ screen_resize(Screen *self, unsigned int lines, unsigned int columns) { clear_selection(&self->selections); clear_selection(&self->url_ranges); self->last_visited_prompt.is_set = false; - /* printf("old_cursor: (%u, %u) new_cursor: (%u, %u) beyond_content: %d\n", self->cursor->x, self->cursor->y, cursor_x, cursor_y, cursor_is_beyond_content); */ #define S(c, w) c->x = MIN(w.after.x, self->columns - 1); c->y = MIN(w.after.y, self->lines - 1); S(self->cursor, cursor); S((&(self->main_savepoint.cursor)), main_saved_cursor); diff --git a/kitty_tests/screen.py b/kitty_tests/screen.py index 2abfda77e..9ad1baf9e 100644 --- a/kitty_tests/screen.py +++ b/kitty_tests/screen.py @@ -332,6 +332,17 @@ class TestScreen(BaseTest): s.resize(s.lines - 1, s.columns) self.ae(x_before, s.cursor.x) + def test_cursor_position_after_resize(self): + # test x position remains the same after resize + s = self.create_screen() + s.draw('abc') + b = s.cursor.x + s.resize(7, s.columns) + self.assertEqual(s.cursor.x, b) + s.cursor.x = 0 + s.resize(5, s.columns) + self.assertEqual(s.cursor.x, 0) + def test_scrollback_fill_after_resize(self): def prepare_screen(content=()): ans = self.create_screen(options={'scrollback_fill_enlarged_window': True})