fix(compatibility): handle cursor movements outside scroll region (#746)

* fix(compatibility): handle cursor movements outside scroll region

* style(fmt): make clippy happy
This commit is contained in:
Aram Drevekenin 2021-09-28 15:41:32 +02:00 committed by GitHub
parent 9227ff0981
commit 8b3287c452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 9 deletions

View file

@ -0,0 +1,42 @@

1foo
2foo
3foo
4foo
5foo
6foo
7foo
8foo
9foo
10foo
11foo
12foo
13foo
14foo
15foo
16foo
17foo
18foo
19foo
20foo
21foo
22foo
23foo
24foo
25foo
26foo
27foo
28foo
29foo
30foo
31foo
32foo
33foo
34foo
35foo

1bar
2bar
3bar
4bar
5zz

View file

@ -883,14 +883,16 @@ impl Grid {
self.viewport.push(new_row);
}
if self.cursor.y == self.height - 1 {
let row_count_to_transfer = 1;
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
row_count_to_transfer,
self.width,
);
self.selection.move_up(1);
if self.scroll_region.is_none() {
let row_count_to_transfer = 1;
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
row_count_to_transfer,
self.width,
);
self.selection.move_up(1);
}
self.output_buffer.update_all_lines();
} else {
self.cursor.y += 1;
@ -1051,7 +1053,11 @@ impl Grid {
} else {
0
};
self.cursor.y = std::cmp::min(scroll_region_bottom, y + y_offset);
if y >= scroll_region_top && y <= scroll_region_bottom {
self.cursor.y = std::cmp::min(scroll_region_bottom, y + y_offset);
} else {
self.cursor.y = std::cmp::min(self.height - 1, y + y_offset);
}
self.pad_lines_until(self.cursor.y, pad_character);
self.pad_current_line_until(self.cursor.x);
}

View file

@ -998,3 +998,15 @@ pub fn scroll_up_increase_width_and_scroll_down() {
}
assert_snapshot!(format!("{:?}", grid));
}
#[test]
pub fn move_cursor_below_scroll_region() {
let mut vte_parser = vte::Parser::new();
let mut grid = Grid::new(34, 114, Palette::default());
let fixture_name = "move_cursor_below_scroll_region";
let content = read_fixture(fixture_name);
for byte in content {
vte_parser.advance(&mut grid, byte);
}
assert_snapshot!(format!("{:?}", grid));
}

View file

@ -0,0 +1,41 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
expression: "format!(\"{:?}\", grid)"
---
00 (C): 7foo
01 (C): 8foo
02 (C): 9foo
03 (C): 10foo
04 (C): 11foo
05 (C): 12foo
06 (C): 13foo
07 (C): 14foo
08 (C): 15foo
09 (C): 16foo
10 (C): 17foo
11 (C): 18foo
12 (C): 19foo
13 (C): 20foo
14 (C): 21foo
15 (C): 22foo
16 (C): 23foo
17 (C): 24foo
18 (C): 25foo
19 (C): 26foo
20 (C): 27foo
21 (C): 28foo
22 (C): 29foo
23 (C): 30foo
24 (C): 31foo
25 (C): 32foo
26 (C): 33foo
27 (C): 34foo
28 (C): 35foo
29 (C):
30 (C):
31 (C):
32 (C):
33 (C): 5zzr
34 (C):