From 56d15238d1a61a539171667e5713cd6939c08d07 Mon Sep 17 00:00:00 2001 From: CismonX Date: Wed, 29 Jul 2026 08:25:40 +0800 Subject: render: fix broken selection on delayed resize Interactive resize of a terminal window breaks current selection, if scrollback is not empty, and option 'resize-delay-ms' is not 0. This behavior is introduced by commit 296e75f4f5, which: - Subtracts selection row by view offset every time render_resize() is called, resulting in bad coordinates. - Does not properly restore the original selection coordinates during the final text reflow stage. --- render.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index cf5f969a..fe2c29ba 100644 --- a/render.c +++ b/render.c @@ -4382,6 +4382,9 @@ delayed_reflow_of_normal_grid(struct terminal *term) xassert(term->interactive_resizing.new_rows > 0); + if (term->grid == &term->normal) + term->selection.coords = term->interactive_resizing.selection_coords; + struct coord *const tracking_points[] = { &term->selection.coords.start, &term->selection.coords.end, @@ -4409,6 +4412,7 @@ delayed_reflow_of_normal_grid(struct terminal *term) term->interactive_resizing.old_screen_rows = 0; term->interactive_resizing.new_rows = 0; term->interactive_resizing.old_hide_cursor = false; + term->interactive_resizing.selection_coords = (struct range){{-1, -1}, {-1, -1}}; /* Invalidate render pointers */ render_wait_for_preapply_damage(term); @@ -4760,8 +4764,11 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) term->interactive_resizing.grid = xmalloc(sizeof(*term->interactive_resizing.grid)); *term->interactive_resizing.grid = term->normal; - if (term->grid == &term->normal) + if (term->grid == &term->normal) { term->interactive_resizing.selection_coords = term->selection.coords; + term->selection.coords.start.row -= term->grid->view; + term->selection.coords.end.row -= term->grid->view; + } } else { /* We'll replace the current temporary grid, with a new * one (again based on the original grid) */ @@ -4799,9 +4806,6 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts) .kitty_kbd = orig->kitty_kbd, }; - term->selection.coords.start.row -= orig->view; - term->selection.coords.end.row -= orig->view; - for (size_t i = 0, j = orig->view; i < term->interactive_resizing.old_screen_rows; i++, j = (j + 1) & (orig->num_rows - 1)) -- cgit v1.3