From bc60782e424359d818a22ffa2ffa3c2dc88ab6fe Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Wed, 1 Jul 2020 06:58:06 +0000 Subject: [PATCH] Fix reflow of empty wrapped cursor line This bug was caused by trying to grow the terminal while the cursor line was wrapped but entirely empty. Resizing the terminal now accounts for the position of the deleted line and moves the cursor up only when the line deleted was above it. The deletion of the line was caused by the shell redrawing itself whenever the cursor is moved. Fixes #3583. --- CHANGELOG.md | 1 + alacritty_terminal/src/grid/mod.rs | 5 ----- alacritty_terminal/src/grid/resize.rs | 17 +++++++++++++++-- alacritty_terminal/src/grid/row.rs | 3 ++- alacritty_terminal/src/term/mod.rs | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0297b1e1..8109b100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Regression in font rendering on macOS - Scroll down escape (`CSI Ps T`) incorrectly pulling lines from history - Dim escape (`CSI 2 m`) support for truecolor text +- Incorrectly deleted lines when increasing width with a prompt wrapped using spaces ## 0.4.3 diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs index fd555d1b..5178ed99 100644 --- a/alacritty_terminal/src/grid/mod.rs +++ b/alacritty_terminal/src/grid/mod.rs @@ -187,11 +187,6 @@ impl Grid { Point { line: self.lines.0 + self.display_offset - point.line.0 - 1, col: point.col } } - /// Return the cursor position in buffer coordinates. - pub fn cursor_buffer_point(&self) -> Point { - Point { line: self.lines.0 - self.cursor.point.line.0 - 1, col: self.cursor.point.col } - } - /// Update the size of the scrollback history. pub fn update_history(&mut self, history_size: usize) { let current_history_size = self.history_size(); diff --git a/alacritty_terminal/src/grid/resize.rs b/alacritty_terminal/src/grid/resize.rs index 796c5859..95a8c2fc 100644 --- a/alacritty_terminal/src/grid/resize.rs +++ b/alacritty_terminal/src/grid/resize.rs @@ -67,10 +67,12 @@ impl Grid { self.scroll_up(&(Line(0)..self.lines), Line(required_scrolling), T::default()); // Clamp cursors to the new viewport size. - self.saved_cursor.point.line = min(self.saved_cursor.point.line, target - 1); self.cursor.point.line = min(self.cursor.point.line, target - 1); } + // Clamp saved cursor, since only primary cursor is scrolled into viewport. + self.saved_cursor.point.line = min(self.saved_cursor.point.line, target - 1); + self.raw.rotate((self.lines - target).0 as isize); self.raw.shrink_visible_lines(target); self.lines = target; @@ -135,7 +137,8 @@ impl Grid { // Reflow cells to previous row. last_row.append(&mut cells); - if row.is_empty() { + let cursor_buffer_line = (self.lines - self.cursor.point.line - 1).0; + if row.is_clear() && (i != cursor_buffer_line || row.len() == 0) { if i + reversed.len() < self.lines.0 { // Add new line and move everything up if we can't pull from history. self.saved_cursor.point.line.0 = self.saved_cursor.point.line.saturating_sub(1); @@ -144,6 +147,16 @@ impl Grid { } else { // Since we removed a line, rotate down the viewport. self.display_offset = self.display_offset.saturating_sub(1); + + // Rotate cursors down if content below them was pulled from history. + if i < cursor_buffer_line { + self.cursor.point.line += 1; + } + + let saved_buffer_line = (self.lines - self.saved_cursor.point.line - 1).0; + if i < saved_buffer_line { + self.saved_cursor.point.line += 1; + } } // Don't push line into the new buffer. diff --git a/alacritty_terminal/src/grid/row.rs b/alacritty_terminal/src/grid/row.rs index bd5411aa..7846a7ae 100644 --- a/alacritty_terminal/src/grid/row.rs +++ b/alacritty_terminal/src/grid/row.rs @@ -130,8 +130,9 @@ impl Row { self.inner = vec; } + /// Check if all cells in the row are empty. #[inline] - pub fn is_empty(&self) -> bool + pub fn is_clear(&self) -> bool where T: GridCell, { diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index bed3f1bc..16e4de92 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1775,7 +1775,7 @@ impl Handler for Term { }, } - let cursor_buffer_line = self.grid.cursor_buffer_point().line; + let cursor_buffer_line = (self.grid.num_lines() - self.grid.cursor.point.line - 1).0; self.selection = self .selection .take() @@ -1858,7 +1858,7 @@ impl Handler for Term { let template = self.grid.cursor.template; let num_lines = self.grid.num_lines().0; - let cursor_buffer_line = self.grid.cursor_buffer_point().line; + let cursor_buffer_line = num_lines - self.grid.cursor.point.line.0 - 1; match mode { ansi::ClearMode::Above => {