fix(compatibility): fix neovim scrolling (#107)

* fix(compatibility): fix neovim scrolling

* style(formatting): make rustfmt happy
This commit is contained in:
Aram Drevekenin 2020-12-17 13:00:44 +01:00 committed by GitHub
parent 38d8e2238d
commit 97d2c8339e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 35 deletions

View file

@ -312,8 +312,8 @@ pub struct Scroll {
viewport_bottom_offset: Option<usize>,
scroll_region: Option<(usize, usize)>, // start line, end line (if set, this is the area the will scroll)
show_cursor: bool,
lines_outside_of_scroll_region: Option<Vec<CanonicalLine>>,
cursor_position_outside_of_scroll_region: Option<CursorPosition>,
alternative_buffer: Option<Vec<CanonicalLine>>,
alternative_cursor_position: Option<CursorPosition>,
}
impl Scroll {
@ -329,8 +329,8 @@ impl Scroll {
viewport_bottom_offset: None,
scroll_region: None,
show_cursor: true,
lines_outside_of_scroll_region: None,
cursor_position_outside_of_scroll_region: None,
alternative_buffer: None,
alternative_cursor_position: None,
}
}
pub fn as_character_lines(&self) -> Vec<Vec<TerminalCharacter>> {
@ -638,33 +638,27 @@ impl Scroll {
let current_column = self.cursor_position.column_index;
self.move_cursor_to(line, current_column);
}
pub fn set_scroll_region(&mut self, top_line: usize, bottom_line: usize) {
if self.scroll_region.is_none() {
self.lines_outside_of_scroll_region = Some(self.canonical_lines.drain(..).collect());
self.cursor_position_outside_of_scroll_region = Some(self.cursor_position);
pub fn move_current_buffer_to_alternative_buffer(&mut self) {
self.alternative_buffer = Some(self.canonical_lines.drain(..).collect());
self.alternative_cursor_position = Some(self.cursor_position);
self.cursor_position.reset();
}
pub fn override_current_buffer_with_alternative_buffer(&mut self) {
if let Some(alternative_buffer) = self.alternative_buffer.as_mut() {
self.canonical_lines = alternative_buffer.drain(..).collect();
}
if let Some(alternative_cursor_position) = self.alternative_cursor_position {
self.cursor_position = alternative_cursor_position;
}
self.alternative_buffer = None;
self.alternative_cursor_position = None;
}
pub fn set_scroll_region(&mut self, top_line: usize, bottom_line: usize) {
self.scroll_region = Some((top_line, bottom_line));
}
pub fn clear_scroll_region(&mut self) {
if let Some(scroll_region) = self.scroll_region_absolute_indices() {
self.canonical_lines.drain(scroll_region.0..scroll_region.1);
self.cursor_position.reset();
self.scroll_region = None;
}
if let Some(lines_outside_of_scroll_region) = self.lines_outside_of_scroll_region.as_mut() {
self.canonical_lines = lines_outside_of_scroll_region.drain(..).collect();
}
if let Some(cursor_position_outside_of_scroll_region) =
self.cursor_position_outside_of_scroll_region
{
self.cursor_position = cursor_position_outside_of_scroll_region;
}
self.lines_outside_of_scroll_region = None;
self.cursor_position_outside_of_scroll_region = None;
}
pub fn set_scroll_region_to_screen_size(&mut self) {
self.scroll_region = Some((0, self.lines_in_view - 1)); // these are indices
}
fn scroll_region_absolute_indices(&mut self) -> Option<(usize, usize)> {
if self.scroll_region.is_none() {
return None;

View file

@ -452,15 +452,6 @@ impl vte::Perform for TerminalPane {
(params[0] as usize - 1, params[1] as usize - 1)
}
};
if params.len() >= 1 && params[0] == 0 {
// this is a hack
//
// the logic should *probably* be:
// if we get an instruction to move outside the scroll region
// (which is 1 indexed, so if we get 0 it's always(?) outside)
// we need to set it to screen size
self.scroll.set_scroll_region_to_screen_size();
}
self.scroll.move_cursor_to(row, col);
} else if c == 'A' {
// move cursor up until edge of screen
@ -481,6 +472,10 @@ impl vte::Perform for TerminalPane {
};
if first_intermediate_is_questionmark {
match params.get(0) {
Some(&1049) => {
self.scroll
.override_current_buffer_with_alternative_buffer();
}
Some(&25) => {
self.scroll.hide_cursor();
self.mark_for_rerender();
@ -503,6 +498,9 @@ impl vte::Perform for TerminalPane {
self.scroll.show_cursor();
self.mark_for_rerender();
}
Some(&1049) => {
self.scroll.move_current_buffer_to_alternative_buffer();
}
Some(&1) => {
self.cursor_key_mode = true;
}