From a1083d18edf14f3b7219f50618281479df812312 Mon Sep 17 00:00:00 2001 From: a5ob7r <12132068+a5ob7r@users.noreply.github.com> Date: Sat, 4 Dec 2021 04:33:21 +0900 Subject: Fix vi cursor moving incorrectly with new output This fixes an issue where the vi cursor would move down one line if it's positioned at the topmost visible line, while at least partially scrolled up into history, when new lines are added to the terminal. This problem is caused by using a display offset of a grid not scrolled yet when scrolling and determining a new vi cursor position. --- CHANGELOG.md | 1 + alacritty_terminal/src/term/mod.rs | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 157c7150..a82835d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Crash when hovering over a match emptied by post-processing - Crash when the vi cursor is on the scrollback and viewport clear is invoked - Freeze when the vi cursor is on the scrollback and scrollback clear is invoked +- Vi cursor on topmost of the display moving downward when scrolled into history with active output ### Removed diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 2ea0afc3..2908aadb 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -587,6 +587,8 @@ impl Term { // Scroll selection. self.selection = self.selection.take().and_then(|s| s.rotate(self, ®ion, lines as i32)); + self.grid.scroll_up(®ion, lines); + // Scroll vi mode cursor. let viewport_top = Line(-(self.grid.display_offset() as i32)); let top = if region.start == 0 { viewport_top } else { region.start }; @@ -594,9 +596,6 @@ impl Term { if (top <= *line) && region.end > *line { *line = max(*line - lines, top); } - - // Scroll from origin to bottom less number of lines. - self.grid.scroll_up(®ion, lines); } fn deccolm(&mut self) @@ -2190,6 +2189,26 @@ mod tests { assert_eq!(term.grid, scrolled_grid); } + #[test] + fn vi_cursor_keep_pos_on_scrollback_buffer() { + let size = SizeInfo::new(5., 10., 1.0, 1.0, 0.0, 0.0, false); + let mut term = Term::new(&Config::default(), size, ()); + + // Create 11 lines of scrollback. + for _ in 0..20 { + term.newline(); + } + + // Enable vi mode. + term.toggle_vi_mode(); + + term.scroll_display(Scroll::Top); + term.vi_mode_cursor.point.line = Line(-11); + + term.linefeed(); + assert_eq!(term.vi_mode_cursor.point.line, Line(-12)); + } + #[test] fn grow_lines_updates_active_cursor_pos() { let mut size = SizeInfo::new(100.0, 10.0, 1.0, 1.0, 0.0, 0.0, false); -- cgit v1.2.3-54-g00ecf