aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2020-12-17 13:00:44 +0100
committerGitHub <noreply@github.com>2020-12-17 13:00:44 +0100
commit97d2c8339e9a3e07c1c4eb8b76e2d7f816f1f56e (patch)
treeb9cc685eb5a5e4699b119bea42ff6c1a5634d58d /src
parentfix(compatibility): handle tab characters properly (#99) (diff)
downloadsl0ppij-97d2c8339e9a3e07c1c4eb8b76e2d7f816f1f56e.tar.gz
sl0ppij-97d2c8339e9a3e07c1c4eb8b76e2d7f816f1f56e.tar.xz
sl0ppij-97d2c8339e9a3e07c1c4eb8b76e2d7f816f1f56e.zip
fix(compatibility): fix neovim scrolling (#107)
* fix(compatibility): fix neovim scrolling * style(formatting): make rustfmt happy
Diffstat (limited to 'src')
-rw-r--r--src/terminal_pane/scroll.rs46
-rw-r--r--src/terminal_pane/terminal_pane.rs16
2 files changed, 27 insertions, 35 deletions
diff --git a/src/terminal_pane/scroll.rs b/src/terminal_pane/scroll.rs
index b6f66be9..886a58d3 100644
--- a/src/terminal_pane/scroll.rs
+++ b/src/terminal_pane/scroll.rs
@@ -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,32 +638,26 @@ 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);
- }
- self.scroll_region = Some((top_line, bottom_line));
+ 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 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;
+ 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(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(alternative_cursor_position) = self.alternative_cursor_position {
+ self.cursor_position = alternative_cursor_position;
}
- 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;
+ 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 set_scroll_region_to_screen_size(&mut self) {
- self.scroll_region = Some((0, self.lines_in_view - 1)); // these are indices
+ pub fn clear_scroll_region(&mut self) {
+ self.scroll_region = None;
}
fn scroll_region_absolute_indices(&mut self) -> Option<(usize, usize)> {
if self.scroll_region.is_none() {
diff --git a/src/terminal_pane/terminal_pane.rs b/src/terminal_pane/terminal_pane.rs
index 0901b8c9..ae0439a9 100644
--- a/src/terminal_pane/terminal_pane.rs
+++ b/src/terminal_pane/terminal_pane.rs
@@ -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;
}