From 6e38cb683a311d848384e68559e6f0dd44abbb01 Mon Sep 17 00:00:00 2001 From: Piotr Kocia Date: Tue, 17 Jun 2025 14:50:20 +0200 Subject: [PATCH] fix selection changing start on mode change --- commands.c | 8 ++++++-- vimode.c | 8 +++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/commands.c b/commands.c index 0b8329b7..6c139aef 100644 --- a/commands.c +++ b/commands.c @@ -47,8 +47,10 @@ cmd_scrollback_up(struct terminal *term, int rows) view, new_view, offset, grid_rows); selection_view_up(term, new_view); + const int delta = + (term->grid->view - new_view) & (term->grid->num_rows - 1); term->grid->view = new_view; - vimode_view_up(term, 0); + vimode_view_up(term, delta); if (rows < term->rows) { term_damage_scroll( @@ -102,8 +104,10 @@ cmd_scrollback_down(struct terminal *term, int rows) view, new_view, offset, grid_rows); selection_view_down(term, new_view); + const int delta = + (new_view - term->grid->view) & (term->grid->num_rows - 1); term->grid->view = new_view; - vimode_view_down(term, 0); + vimode_view_down(term, delta); if (rows < term->rows) { term_damage_scroll( diff --git a/vimode.c b/vimode.c index 24da5955..c290ba41 100644 --- a/vimode.c +++ b/vimode.c @@ -458,17 +458,16 @@ void vimode_cancel(struct terminal *term) render_refresh(term); } -void vimode_view_up(struct terminal *term, int const delta) +void vimode_view_up(struct terminal *const term, int const delta) { if (!term->vimode.active) { return; } - damage_cursor_cell(term); - term->vimode.cursor.row += delta; clip_cursor_to_view(term); update_selection(term); update_highlights(term); + term->vimode.selection.start.row += delta; } void vimode_view_down(struct terminal *const term, int const delta) @@ -477,11 +476,10 @@ void vimode_view_down(struct terminal *const term, int const delta) return; } - damage_cursor_cell(term); - term->vimode.cursor.row -= delta; clip_cursor_to_view(term); update_selection(term); update_highlights(term); + term->vimode.selection.start.row -= delta; } static ssize_t matches_cell(const struct terminal *term,