diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-11-13 05:40:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 08:40:09 +0300 |
commit | 9a7844987693909925b8663d8aa905231d291410 (patch) | |
tree | e99b99bcbd0fc40aa1938fc203357321ec024777 /alacritty_terminal/src/grid | |
parent | b6d94e7b13eb9a14edea843a79c6d86b5b6d8803 (diff) | |
download | alacritty-9a7844987693909925b8663d8aa905231d291410.tar.gz alacritty-9a7844987693909925b8663d8aa905231d291410.zip |
Add ability to select text during search
This removes the restriction of not being able to select text while the
search is active, making it a bit less jarring of a UX when the user
tries to interact with the terminal during search.
Since the selection was used during vi-less search to highlight the
focused match, there is now an option for a focused match color, which
uses the inverted normal match color by default. This focused match is
used for both search modes.
Other mouse interactions are now also possible during search, like
opening URLs or clicking inside of mouse mode applications.
Diffstat (limited to 'alacritty_terminal/src/grid')
-rw-r--r-- | alacritty_terminal/src/grid/mod.rs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs index 70dbc936..21e7e2f9 100644 --- a/alacritty_terminal/src/grid/mod.rs +++ b/alacritty_terminal/src/grid/mod.rs @@ -1,7 +1,7 @@ //! A specialized 2D grid implementation optimized for use in a terminal. use std::cmp::{max, min}; -use std::ops::{Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo}; +use std::ops::{Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo}; use serde::{Deserialize, Serialize}; @@ -368,6 +368,30 @@ impl<T> Grid<T> { } } + // Clamp a buffer point based range to the viewport. + // + // This will make sure the content within the range is visible and return `None` whenever the + // entire range is outside the visible region. + pub fn clamp_buffer_range_to_visible( + &self, + range: &RangeInclusive<Point<usize>>, + ) -> Option<RangeInclusive<Point>> { + let start = range.start(); + let end = range.end(); + + // Check if the range is completely offscreen + let viewport_end = self.display_offset; + let viewport_start = viewport_end + self.lines.0 - 1; + if end.line > viewport_start || start.line < viewport_end { + return None; + } + + let start = self.clamp_buffer_to_visible(*start); + let end = self.clamp_buffer_to_visible(*end); + + Some(start..=end) + } + /// Convert viewport relative point to global buffer indexing. #[inline] pub fn visible_to_buffer(&self, point: Point) -> Point<usize> { @@ -759,12 +783,8 @@ impl<'a, T: 'a> DisplayIter<'a, T> { self.offset } - pub fn column(&self) -> Column { - self.col - } - - pub fn line(&self) -> Line { - self.line + pub fn point(&self) -> Point { + Point::new(self.line, self.col) } } |