diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-03-07 22:17:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-07 22:17:38 +0000 |
commit | 64a3115648d354731ef08c2de8b2168b9326b7b5 (patch) | |
tree | c9121ed2e475ed2b531d8f8a1c01d9f000d74769 /alacritty_terminal/src/term | |
parent | de5d770416eb6ea5567b2b46874b8e35b084b9e1 (diff) | |
download | alacritty-64a3115648d354731ef08c2de8b2168b9326b7b5.tar.gz alacritty-64a3115648d354731ef08c2de8b2168b9326b7b5.zip |
Fix selection with invisible start and end
This resolves an issue with the selection clamping, where no selection
would be rendered at all when the start was above the viewport while the
end was below it.
Diffstat (limited to 'alacritty_terminal/src/term')
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index d545d686..660aeb79 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -222,9 +222,8 @@ impl<'a, C> RenderableCellsIter<'a, C> { ) -> RenderableCellsIter<'b, C> { let grid = &term.grid; let num_cols = grid.num_cols(); - let num_lines = grid.num_lines(); - let cursor_offset = grid.line_to_offset(term.cursor.point.line); + let cursor_offset = grid.num_lines().0 - term.cursor.point.line.0 - 1; let inner = grid.display_iter(); let selection_range = selection.and_then(|span| { @@ -235,28 +234,14 @@ impl<'a, C> RenderableCellsIter<'a, C> { }; // Get on-screen lines of the selection's locations - let start = term.buffer_to_visible(span.start); - let end = term.buffer_to_visible(span.end); - - // Clamp visible selection to the viewport - let (mut start, mut end) = match (start, end) { - (Some(start), Some(end)) => (start, end), - (Some(start), None) => { - let end = Point::new(num_lines.0 - 1, num_cols - 1); - (start, end) - }, - (None, Some(end)) => { - let start = Point::new(0, Column(0)); - (start, end) - }, - (None, None) => return None, - }; + let mut start = grid.clamp_buffer_to_visible(span.start); + let mut end = grid.clamp_buffer_to_visible(span.end); // Trim start/end with partially visible block selection start.col = max(limit_start, start.col); end.col = min(limit_end, end.col); - Some(SelectionRange::new(start.into(), end.into(), span.is_block)) + Some(SelectionRange::new(start, end, span.is_block)) }); // Load cursor glyph @@ -1085,10 +1070,6 @@ impl<T> Term<T> { self.grid.visible_to_buffer(point) } - pub fn buffer_to_visible(&self, point: impl Into<Point<usize>>) -> Option<Point<usize>> { - self.grid.buffer_to_visible(point) - } - /// Access to the raw grid data structure /// /// This is a bit of a hack; when the window is closed, the event processor |