From 1887722ef5b6ac1c1f0e4e4f62cbb02b609c1d4b Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 28 Sep 2018 22:07:24 +0000 Subject: Fix rendering of selections outside the viewport When rendering selections with both start and end outside of the visible area, Alacritty would assume that both start and end are either above or below the viewport and not render the selection at all. To fix this the `buffer_line_to_visible` method now returns a `ViewportPosition` instead of an `Option`, this allows giving more feedback about where outside of the visible region the line is using the `ViewportPosition::Above` and `ViewportPosition::Below` variants. Using these newly introduced variants, a selection spanning the whole screen is now rendered if the selection should go from above the visible area to below it. This fixes #1557. --- src/grid/mod.rs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'src/grid/mod.rs') diff --git a/src/grid/mod.rs b/src/grid/mod.rs index b8feb421..9e15bd02 100644 --- a/src/grid/mod.rs +++ b/src/grid/mod.rs @@ -116,6 +116,13 @@ pub enum Scroll { Bottom, } +#[derive(Copy, Clone)] +pub enum ViewportPosition { + Visible(Line), + Above, + Below, +} + impl Grid { pub fn new(lines: index::Line, cols: index::Column, scrollback: usize, template: T) -> Grid { let raw = Storage::with_capacity(lines, Row::new(cols, &template)); @@ -137,18 +144,14 @@ impl Grid { } } - pub fn buffer_to_visible(&self, point: Point) -> Point { - Point { - line: self.buffer_line_to_visible(point.line).expect("Line not visible"), - col: point.col - } - } - - pub fn buffer_line_to_visible(&self, line: usize) -> Option { - if line >= self.display_offset { - self.offset_to_line(line - self.display_offset) + pub fn buffer_line_to_visible(&self, line: usize) -> ViewportPosition { + let offset = line.saturating_sub(self.display_offset); + if line < self.display_offset { + ViewportPosition::Below + } else if offset >= *self.num_lines() { + ViewportPosition::Above } else { - None + ViewportPosition::Visible(self.lines - offset - 1) } } @@ -300,14 +303,6 @@ impl Grid { *(self.num_lines() - line - 1) } - pub fn offset_to_line(&self, offset: usize) -> Option { - if offset < *self.num_lines() { - Some(self.lines - offset - 1) - } else { - None - } - } - #[inline] pub fn scroll_down( &mut self, -- cgit