diff options
Diffstat (limited to 'alacritty_terminal/src/term/mod.rs')
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 9b7a4c35..2ea0afc3 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1424,6 +1424,9 @@ impl<T: EventListener> Handler for Term<T> { self.grid.reset_region(..); } else { self.grid.clear_viewport(); + + self.vi_mode_cursor.point.line = + self.vi_mode_cursor.point.line.grid_clamp(self, Boundary::Cursor); } self.selection = None; @@ -1431,6 +1434,9 @@ impl<T: EventListener> Handler for Term<T> { ansi::ClearMode::Saved if self.history_size() > 0 => { self.grid.clear_history(); + self.vi_mode_cursor.point.line = + self.vi_mode_cursor.point.line.grid_clamp(self, Boundary::Cursor); + self.selection = self.selection.take().filter(|s| !s.intersects_range(..Line(0))); }, // We have no history to clear. @@ -2119,6 +2125,50 @@ mod tests { } #[test] + fn clear_viewport_set_vi_cursor_into_viewport() { + let size = SizeInfo::new(10.0, 20.0, 1.0, 1.0, 0.0, 0.0, false); + let mut term = Term::new(&Config::default(), size, ()); + + // Create 10 lines of scrollback. + for _ in 0..29 { + term.newline(); + } + + // Change the display area and the vi cursor position. + term.scroll_display(Scroll::Top); + term.vi_mode_cursor.point = Point::new(Line(-5), Column(3)); + + // Clear the viewport. + term.clear_screen(ansi::ClearMode::All); + + assert_eq!(term.grid.display_offset(), 0); + assert_eq!(term.vi_mode_cursor.point.line.0, 0); + assert_eq!(term.vi_mode_cursor.point.column.0, 3); + } + + #[test] + fn clear_scrollback_set_vi_cursor_into_viewport() { + let size = SizeInfo::new(10.0, 20.0, 1.0, 1.0, 0.0, 0.0, false); + let mut term = Term::new(&Config::default(), size, ()); + + // Create 10 lines of scrollback. + for _ in 0..29 { + term.newline(); + } + + // Change the display area and the vi cursor position. + term.scroll_display(Scroll::Top); + term.vi_mode_cursor.point = Point::new(Line(-5), Column(3)); + + // Clear the scrollback buffer. + term.clear_screen(ansi::ClearMode::Saved); + + assert_eq!(term.grid.display_offset(), 0); + assert_eq!(term.vi_mode_cursor.point.line.0, 0); + assert_eq!(term.vi_mode_cursor.point.column.0, 3); + } + + #[test] fn clear_saved_lines() { let size = SizeInfo::new(21.0, 51.0, 3.0, 3.0, 0.0, 0.0, false); let mut term = Term::new(&Config::default(), size, ()); |