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.
This commit is contained in:
a5ob7r 2021-12-04 04:33:21 +09:00 committed by GitHub
parent 7e736c00f6
commit a1083d18ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -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

View File

@ -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)
@ -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);