summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/grid
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-03-24 01:29:07 +0000
committerGitHub <noreply@github.com>2020-03-24 01:29:07 +0000
commitc35dbc96575f6147de97be15c5134bc7fabe50bd (patch)
treee905e4de6dbae5a5126fb792b567c91d6e637c2c /alacritty_terminal/src/grid
parentc9c5fbbe2bd522c55af041e84d6a222c059555b1 (diff)
downloadalacritty-c35dbc96575f6147de97be15c5134bc7fabe50bd.tar.gz
alacritty-c35dbc96575f6147de97be15c5134bc7fabe50bd.zip
Fix cursor position after alt screen resize
This fixes a regression introduced in 4cc6421, which ignored the main grid's cursor when increasing the number of lines available, causing incorrect cursor position after restoring to the primary screen. Additionally another similar bug has been fixed where the grid was not scrolled correctly when shrinking while in the alternate screen. When the grid is resized multiple lines at once, there was also an issue with Alacritty either pulling all lines from history or none at all, instead of mixing both approaches and pulling just what is required. This lead to incorrect cursor positions when the resize could partially make use of history. Fixes #3499.
Diffstat (limited to 'alacritty_terminal/src/grid')
-rw-r--r--alacritty_terminal/src/grid/mod.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs
index 85d1a0bb..97353647 100644
--- a/alacritty_terminal/src/grid/mod.rs
+++ b/alacritty_terminal/src/grid/mod.rs
@@ -205,8 +205,8 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> {
}
match self.lines.cmp(&lines) {
- Ordering::Less => self.grow_lines(lines, template),
- Ordering::Greater => self.shrink_lines(lines),
+ Ordering::Less => self.grow_lines(lines, cursor_pos, template),
+ Ordering::Greater => self.shrink_lines(lines, cursor_pos, template),
Ordering::Equal => (),
}
@@ -236,17 +236,22 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> {
/// Alacritty keeps the cursor at the bottom of the terminal as long as there
/// is scrollback available. Once scrollback is exhausted, new lines are
/// simply added to the bottom of the screen.
- fn grow_lines(&mut self, new_line_count: Line, template: &T) {
+ fn grow_lines(&mut self, new_line_count: Line, cursor_pos: &mut Point, template: &T) {
let lines_added = new_line_count - self.lines;
// Need to "resize" before updating buffer
self.raw.grow_visible_lines(new_line_count, Row::new(self.cols, template));
self.lines = new_line_count;
- // Move existing lines up if there is no scrollback to fill new lines
let history_size = self.history_size();
- if lines_added.0 > history_size {
- self.scroll_up(&(Line(0)..new_line_count), lines_added - history_size, template);
+ let from_history = min(history_size, lines_added.0);
+
+ // Move cursor down for all lines pulled from history
+ cursor_pos.line += from_history;
+
+ if from_history != lines_added.0 {
+ // Move existing lines up for every line that couldn't be pulled from history
+ self.scroll_up(&(Line(0)..new_line_count), lines_added - from_history, template);
}
self.decrease_scroll_limit(*lines_added);
@@ -437,11 +442,15 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> {
/// of the terminal window.
///
/// Alacritty takes the same approach.
- fn shrink_lines(&mut self, target: Line) {
- let prev = self.lines;
+ fn shrink_lines(&mut self, target: Line, cursor_pos: &mut Point, template: &T) {
+ // Scroll up to keep cursor inside the window
+ let required_scrolling = (cursor_pos.line + 1).saturating_sub(target.0);
+ if required_scrolling > 0 {
+ self.scroll_up(&(Line(0)..self.lines), Line(required_scrolling), template);
+ }
self.selection = None;
- self.raw.rotate(*prev as isize - *target as isize);
+ self.raw.rotate((self.lines - target).0 as isize);
self.raw.shrink_visible_lines(target);
self.lines = target;
}