Fix cursor position at x=0 changing to x=1 on resize

Fixes #5635
This commit is contained in:
Kovid Goyal 2022-10-31 08:03:42 +05:30
parent e0b4c7edc5
commit 16b322616a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 15 additions and 2 deletions

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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;

View File

@ -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);

View File

@ -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})