From fe749cf0adee1be93fd3473f6d3533fbe892e3dc Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Sun, 22 Apr 2018 14:39:55 +0200 Subject: Fix order of lines after resize There was an issue where the lines would be messed up when the terminal was resized, this was because lines were just added/removed at the end of the buffer instead of the actual end of the terminal (since the end of the terminal might be in the middle of the buffer). This has been fixed by relying on `self.zero` to determine the position of the start of the terminal and then calculating where lines have to be inserted/removed. Some tests have also been added with documentation that should make it a little easier to understand how the process works and how the raw buffer is layed out. This should all work no matter how big the scrollback history and even when the currenty viewport is not at the bottom of the terminal output. --- src/grid/mod.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/grid/mod.rs') diff --git a/src/grid/mod.rs b/src/grid/mod.rs index e42e5cfa..bc288e3b 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -240,16 +240,9 @@ impl Grid { let lines_added = new_line_count - self.lines; // Need to "resize" before updating buffer - self.raw.set_visible_lines(new_line_count); + self.raw.grow_visible_lines(new_line_count, Row::new(self.cols, template)); self.lines = new_line_count; - // Fill up the history with empty lines - if self.raw.len() < self.raw.capacity() { - for _ in self.raw.len()..self.raw.capacity() { - self.raw.push(Row::new(self.cols, &template)); - } - } - // Add new lines to bottom self.scroll_up(&(Line(0)..new_line_count), lines_added, template); @@ -277,7 +270,7 @@ impl Grid { self.selection = None; self.raw.rotate(*prev as isize - *target as isize); - self.raw.set_visible_lines(target); + self.raw.shrink_visible_lines(target); self.lines = target; } -- cgit