From 296e75f4f54f56be7d36fcccb032dca9e5be959b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 27 Mar 2023 16:53:41 +0200 Subject: [PATCH] =?UTF-8?q?render:=20fix=20glitchy=20selection=20while=20r?= =?UTF-8?q?esizing=20the=20=E2=80=98normal=E2=80=99=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The selection coordinates are in absolute row numbers. As such, selection breaks when interactively resizing the normal grid, since we then instantiate a temporary grid mapping directly to the current viewport (for performance reason, to avoid reflowing the entire grid over and over again). Fix by stashing the actual selection coordinates, and ajusting the "active" ones to the temporary grid. --- render.c | 6 ++++++ terminal.h | 1 + 2 files changed, 7 insertions(+) diff --git a/render.c b/render.c index 9c701000..2aba3237 100644 --- a/render.c +++ b/render.c @@ -3976,6 +3976,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) term->interactive_resizing.old_hide_cursor = term->hide_cursor; term->interactive_resizing.grid = xmalloc(sizeof(*term->interactive_resizing.grid)); *term->interactive_resizing.grid = term->normal; + term->interactive_resizing.selection_coords = term->selection.coords; } else { /* We’ll replace the current temporary grid, with a new * one (again based on the original grid) */ @@ -4013,6 +4014,9 @@ maybe_resize(struct terminal *term, int width, int height, bool force) .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)) @@ -4069,6 +4073,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) free(term->interactive_resizing.grid); term->hide_cursor = term->interactive_resizing.old_hide_cursor; + term->selection.coords = term->interactive_resizing.selection_coords; old_rows = term->interactive_resizing.old_screen_rows; @@ -4076,6 +4081,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) 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}}; term_ptmx_resume(term); } diff --git a/terminal.h b/terminal.h index ec5560cd..21236797 100644 --- a/terminal.h +++ b/terminal.h @@ -604,6 +604,7 @@ struct terminal { int old_cols; /* term->cols before resize started */ int old_hide_cursor; /* term->hide_cursor before resize started */ int new_rows; /* New number of scrollback rows */ + struct range selection_coords; } interactive_resizing; struct {