diff options
author | Joe Wilm <joe@jwilm.com> | 2018-03-05 09:57:34 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2018-06-02 09:34:28 -0700 |
commit | 8ef062efd94975885776e61b6df936088b018da0 (patch) | |
tree | 34567e47784b1d2b0bc82fffac952a18ad4c6c1e /src/term/mod.rs | |
parent | ef3c384540b31004a423ada778ed5c02d90e68c6 (diff) | |
download | r-alacritty-8ef062efd94975885776e61b6df936088b018da0.tar.gz r-alacritty-8ef062efd94975885776e61b6df936088b018da0.tar.bz2 r-alacritty-8ef062efd94975885776e61b6df936088b018da0.zip |
Move selection into Grid
Supporting selections with scrollback has two major components:
1. Grid needs access to Selection so that it may update the scroll
position as the terminal text changes.
2. Selection needs to be implemented in terms of buffer offsets -- NOT
lines -- and be updated when Storage is rotated.
This commit implements the first part.
Diffstat (limited to 'src/term/mod.rs')
-rw-r--r-- | src/term/mod.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs index 493086a7..9eeabc31 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -769,6 +769,14 @@ impl SizeInfo { impl Term { + pub fn selection(&self) -> &Option<Selection> { + &self.grid.selection + } + + pub fn selection_mut(&mut self) -> &mut Option<Selection> { + &mut self.grid.selection + } + #[inline] pub fn get_next_title(&mut self) -> Option<String> { self.next_title.take() @@ -865,7 +873,7 @@ impl Term { self.dirty } - pub fn string_from_selection(&self, span: &Span) -> String { + pub fn selection_to_string(&self) -> Option<String> { /// Need a generic push() for the Append trait trait PushChar { fn push_char(&mut self, c: char); @@ -921,6 +929,9 @@ impl Term { } } + let selection = self.grid.selection.clone()?; + let span = selection.to_span(self)?; + let mut res = String::new(); let (start, end) = span.to_locations(); @@ -957,7 +968,7 @@ impl Term { } } - res + Some(res) } /// Convert the given pixel values to a grid coordinate @@ -986,10 +997,9 @@ impl Term { pub fn renderable_cells<'b>( &'b self, config: &'b Config, - selection: Option<&'b Selection>, window_focused: bool, ) -> RenderableCellsIter { - let selection = selection.and_then(|s| s.to_span(self)) + let selection = self.grid.selection.as_ref().and_then(|s| s.to_span(self)) .map(|span| span.to_range()); let cursor = if window_focused { self.cursor_style.unwrap_or(self.default_cursor_style) @@ -1031,6 +1041,9 @@ impl Term { return; } + self.grid.selection = None; + self.alt_grid.selection = None; + // Should not allow less than 1 col, causes all sorts of checks to be required. if num_cols <= Column(1) { num_cols = Column(2); |