From 2df8f860b960d7c96efaf4f059fe2fbbdce82bcc Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sat, 25 Mar 2023 00:07:20 +0100 Subject: Fix selection rotation on the last line This fixes an issue with terminal resizes when the selection is on the last line. Alacritty would fail to rotate lines and keep the selection in the same line index whenever the terminal line count was grown or shrunk. This issue occurred due to the range passed to the selection's rotate function still being based on the old terminal size, which caused the initial or target state of the rotation to be outside of the terminal bounds. Closes #6698. --- alacritty_terminal/src/term/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'alacritty_terminal/src') diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index fe9c7794..3513aa0e 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -611,6 +611,10 @@ impl Term { delta = cmp::min(cmp::max(delta, min_delta), history_size as i32); self.vi_mode_cursor.point.line += delta; + let is_alt = self.mode.contains(TermMode::ALT_SCREEN); + self.grid.resize(!is_alt, num_lines, num_cols); + self.inactive_grid.resize(is_alt, num_lines, num_cols); + // Invalidate selection and tabs only when necessary. if old_cols != num_cols { self.selection = None; @@ -618,14 +622,11 @@ impl Term { // Recreate tabs list. self.tabs.resize(num_cols); } else if let Some(selection) = self.selection.take() { - let range = Line(0)..Line(num_lines as i32); + let max_lines = cmp::max(num_lines, old_lines) as i32; + let range = Line(0)..Line(max_lines); self.selection = selection.rotate(self, &range, -delta); } - let is_alt = self.mode.contains(TermMode::ALT_SCREEN); - self.grid.resize(!is_alt, num_lines, num_cols); - self.inactive_grid.resize(is_alt, num_lines, num_cols); - // Clamp vi cursor to viewport. let vi_point = self.vi_mode_cursor.point; let viewport_top = Line(-(self.grid.display_offset() as i32)); -- cgit