summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal
diff options
context:
space:
mode:
authora5ob7r <12132068+a5ob7r@users.noreply.github.com>2021-12-04 04:33:21 +0900
committerGitHub <noreply@github.com>2021-12-03 19:33:21 +0000
commita1083d18edf14f3b7219f50618281479df812312 (patch)
tree8b831b564edc4e44bd3400d615510ed1d8ce7220 /alacritty_terminal
parent7e736c00f68ca133ca3380c1ddd78ba61ced1f8e (diff)
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.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r--alacritty_terminal/src/term/mod.rs25
1 files changed, 22 insertions, 3 deletions
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<T> Term<T> {
// Scroll selection.
self.selection = self.selection.take().and_then(|s| s.rotate(self, &region, lines as i32));
+ self.grid.scroll_up(&region, 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<T> Term<T> {
if (top <= *line) && region.end > *line {
*line = max(*line - lines, top);
}
-
- // Scroll from origin to bottom less number of lines.
- self.grid.scroll_up(&region, lines);
}
fn deccolm(&mut self)
@@ -2191,6 +2190,26 @@ mod tests {
}
#[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);
let mut term = Term::new(&Config::default(), size, ());