fix(compatibility): fix neovim scrolling (#107)
* fix(compatibility): fix neovim scrolling * style(formatting): make rustfmt happy
This commit is contained in:
parent
38d8e2238d
commit
97d2c8339e
2 changed files with 27 additions and 35 deletions
|
|
@ -312,8 +312,8 @@ pub struct Scroll {
|
||||||
viewport_bottom_offset: Option<usize>,
|
viewport_bottom_offset: Option<usize>,
|
||||||
scroll_region: Option<(usize, usize)>, // start line, end line (if set, this is the area the will scroll)
|
scroll_region: Option<(usize, usize)>, // start line, end line (if set, this is the area the will scroll)
|
||||||
show_cursor: bool,
|
show_cursor: bool,
|
||||||
lines_outside_of_scroll_region: Option<Vec<CanonicalLine>>,
|
alternative_buffer: Option<Vec<CanonicalLine>>,
|
||||||
cursor_position_outside_of_scroll_region: Option<CursorPosition>,
|
alternative_cursor_position: Option<CursorPosition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scroll {
|
impl Scroll {
|
||||||
|
|
@ -329,8 +329,8 @@ impl Scroll {
|
||||||
viewport_bottom_offset: None,
|
viewport_bottom_offset: None,
|
||||||
scroll_region: None,
|
scroll_region: None,
|
||||||
show_cursor: true,
|
show_cursor: true,
|
||||||
lines_outside_of_scroll_region: None,
|
alternative_buffer: None,
|
||||||
cursor_position_outside_of_scroll_region: None,
|
alternative_cursor_position: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn as_character_lines(&self) -> Vec<Vec<TerminalCharacter>> {
|
pub fn as_character_lines(&self) -> Vec<Vec<TerminalCharacter>> {
|
||||||
|
|
@ -638,32 +638,26 @@ impl Scroll {
|
||||||
let current_column = self.cursor_position.column_index;
|
let current_column = self.cursor_position.column_index;
|
||||||
self.move_cursor_to(line, current_column);
|
self.move_cursor_to(line, current_column);
|
||||||
}
|
}
|
||||||
pub fn set_scroll_region(&mut self, top_line: usize, bottom_line: usize) {
|
pub fn move_current_buffer_to_alternative_buffer(&mut self) {
|
||||||
if self.scroll_region.is_none() {
|
self.alternative_buffer = Some(self.canonical_lines.drain(..).collect());
|
||||||
self.lines_outside_of_scroll_region = Some(self.canonical_lines.drain(..).collect());
|
self.alternative_cursor_position = Some(self.cursor_position);
|
||||||
self.cursor_position_outside_of_scroll_region = 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));
|
self.scroll_region = Some((top_line, bottom_line));
|
||||||
}
|
}
|
||||||
pub fn clear_scroll_region(&mut self) {
|
pub fn clear_scroll_region(&mut self) {
|
||||||
if let Some(scroll_region) = self.scroll_region_absolute_indices() {
|
self.scroll_region = None;
|
||||||
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)> {
|
fn scroll_region_absolute_indices(&mut self) -> Option<(usize, usize)> {
|
||||||
if self.scroll_region.is_none() {
|
if self.scroll_region.is_none() {
|
||||||
|
|
|
||||||
|
|
@ -452,15 +452,6 @@ impl vte::Perform for TerminalPane {
|
||||||
(params[0] as usize - 1, params[1] as usize - 1)
|
(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);
|
self.scroll.move_cursor_to(row, col);
|
||||||
} else if c == 'A' {
|
} else if c == 'A' {
|
||||||
// move cursor up until edge of screen
|
// move cursor up until edge of screen
|
||||||
|
|
@ -481,6 +472,10 @@ impl vte::Perform for TerminalPane {
|
||||||
};
|
};
|
||||||
if first_intermediate_is_questionmark {
|
if first_intermediate_is_questionmark {
|
||||||
match params.get(0) {
|
match params.get(0) {
|
||||||
|
Some(&1049) => {
|
||||||
|
self.scroll
|
||||||
|
.override_current_buffer_with_alternative_buffer();
|
||||||
|
}
|
||||||
Some(&25) => {
|
Some(&25) => {
|
||||||
self.scroll.hide_cursor();
|
self.scroll.hide_cursor();
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
|
|
@ -503,6 +498,9 @@ impl vte::Perform for TerminalPane {
|
||||||
self.scroll.show_cursor();
|
self.scroll.show_cursor();
|
||||||
self.mark_for_rerender();
|
self.mark_for_rerender();
|
||||||
}
|
}
|
||||||
|
Some(&1049) => {
|
||||||
|
self.scroll.move_current_buffer_to_alternative_buffer();
|
||||||
|
}
|
||||||
Some(&1) => {
|
Some(&1) => {
|
||||||
self.cursor_key_mode = true;
|
self.cursor_key_mode = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue