aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/term
diff options
context:
space:
mode:
authora5ob7r <12132068+a5ob7r@users.noreply.github.com>2021-07-05 05:01:29 +0900
committerGitHub <noreply@github.com>2021-07-04 20:01:29 +0000
commit0486c7cb138564422a11d14ce002dd121327d700 (patch)
treee89ee9ff713fdf656aa1fb1efe52db018b11edf9 /alacritty_terminal/src/term
parent9e7655ec03aeacfd13efe3b0b304f86bf1da5e11 (diff)
downloadalacritty-0486c7cb138564422a11d14ce002dd121327d700.tar.gz
alacritty-0486c7cb138564422a11d14ce002dd121327d700.zip
Fix vi cursor motion with ScrollPage* actions
This fixes the regression that vi cursor doesn't move to appropriate position to emulate vi/vim after invokes `ScrollPage*`. To emulate vi/vim the cursor should move up/down some lines if the viewport on topmost scrollback buffer or on bottommost one when invokes `ScrollPage*` action. Otherwise the cursor should look like no movement relatively on viewport.
Diffstat (limited to 'alacritty_terminal/src/term')
-rw-r--r--alacritty_terminal/src/term/mod.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs
index f25bf1ac..ccec0166 100644
--- a/alacritty_terminal/src/term/mod.rs
+++ b/alacritty_terminal/src/term/mod.rs
@@ -1933,6 +1933,62 @@ mod tests {
use crate::term::cell::{Cell, Flags};
#[test]
+ fn scroll_display_page_up() {
+ let size = SizeInfo::new(5., 10., 1.0, 1.0, 0.0, 0.0, false);
+ let mut term = Term::new(&MockConfig::default(), size, ());
+
+ // Create 11 lines of scrollback.
+ for _ in 0..20 {
+ term.newline();
+ }
+
+ // Scrollable amount to top is 11.
+ term.scroll_display(Scroll::PageUp);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(-1), Column(0)));
+ assert_eq!(term.grid.display_offset(), 10);
+
+ // Scrollable amount to top is 1.
+ term.scroll_display(Scroll::PageUp);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(-2), Column(0)));
+ assert_eq!(term.grid.display_offset(), 11);
+
+ // Scrollable amount to top is 0.
+ term.scroll_display(Scroll::PageUp);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(-2), Column(0)));
+ assert_eq!(term.grid.display_offset(), 11);
+ }
+
+ #[test]
+ fn scroll_display_page_down() {
+ let size = SizeInfo::new(5., 10., 1.0, 1.0, 0.0, 0.0, false);
+ let mut term = Term::new(&MockConfig::default(), size, ());
+
+ // Create 11 lines of scrollback.
+ for _ in 0..20 {
+ term.newline();
+ }
+
+ // Change display_offset to topmost.
+ term.grid_mut().scroll_display(Scroll::Top);
+ term.vi_mode_cursor = ViModeCursor::new(Point::new(Line(-11), Column(0)));
+
+ // Scrollable amount to bottom is 11.
+ term.scroll_display(Scroll::PageDown);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(-1), Column(0)));
+ assert_eq!(term.grid.display_offset(), 1);
+
+ // Scrollable amount to bottom is 1.
+ term.scroll_display(Scroll::PageDown);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(0), Column(0)));
+ assert_eq!(term.grid.display_offset(), 0);
+
+ // Scrollable amount to bottom is 0.
+ term.scroll_display(Scroll::PageDown);
+ assert_eq!(term.vi_mode_cursor.point, Point::new(Line(0), Column(0)));
+ assert_eq!(term.grid.display_offset(), 0);
+ }
+
+ #[test]
fn semantic_selection_works() {
let size = SizeInfo::new(5., 3., 1.0, 1.0, 0.0, 0.0, false);
let mut term = Term::new(&MockConfig::default(), size, ());