diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2020-06-26 19:04:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 16:04:55 +0000 |
commit | 8a39346b753528091ccd0c933a216db7f27a7321 (patch) | |
tree | 82fbbabf69511670c89de9e6702bf9caac730edc /alacritty_terminal/src/term/mod.rs | |
parent | 6c8966f426552065f2846c0c1f555d02aba98141 (diff) | |
download | alacritty-8a39346b753528091ccd0c933a216db7f27a7321.tar.gz alacritty-8a39346b753528091ccd0c933a216db7f27a7321.zip |
Clear selection on clear line/screen escapes
Selection is now cleared if clear line or clear screen escape sequences
are clearing content behind it.
Diffstat (limited to 'alacritty_terminal/src/term/mod.rs')
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 33d2e14e..77ad826a 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -1763,6 +1763,12 @@ impl<T: EventListener> Handler for Term<T> { } }, } + + let cursor_buffer_line = self.grid.cursor_buffer_point().line; + self.selection = self + .selection + .take() + .filter(|s| !s.intersects_range(cursor_buffer_line..=cursor_buffer_line)); } /// Set the indexed color value. @@ -1840,8 +1846,8 @@ impl<T: EventListener> Handler for Term<T> { trace!("Clearing screen: {:?}", mode); let template = self.grid.cursor.template; - // Remove active selections. - self.selection = None; + let num_lines = self.grid.num_lines().0; + let cursor_buffer_line = self.grid.cursor_buffer_point().line; match mode { ansi::ClearMode::Above => { @@ -1858,15 +1864,24 @@ impl<T: EventListener> Handler for Term<T> { for cell in &mut self.grid[cursor.line][..end] { cell.reset(&template); } + + self.selection = self + .selection + .take() + .filter(|s| !s.intersects_range(cursor_buffer_line..num_lines)); }, ansi::ClearMode::Below => { let cursor = self.grid.cursor.point; for cell in &mut self.grid[cursor.line][cursor.col..] { cell.reset(&template); } - if cursor.line < self.grid.num_lines() - 1 { + + if cursor.line.0 < num_lines - 1 { self.grid.region_mut((cursor.line + 1)..).each(|cell| cell.reset(&template)); } + + self.selection = + self.selection.take().filter(|s| !s.intersects_range(..=cursor_buffer_line)); }, ansi::ClearMode::All => { if self.mode.contains(TermMode::ALT_SCREEN) { @@ -1875,8 +1890,16 @@ impl<T: EventListener> Handler for Term<T> { let template = Cell { bg: template.bg, ..Cell::default() }; self.grid.clear_viewport(template); } + + self.selection = self.selection.take().filter(|s| !s.intersects_range(..num_lines)); + }, + ansi::ClearMode::Saved if self.grid.history_size() > 0 => { + self.grid.clear_history(); + + self.selection = self.selection.take().filter(|s| !s.intersects_range(num_lines..)); }, - ansi::ClearMode::Saved => self.grid.clear_history(), + // We have no history to clear. + ansi::ClearMode::Saved => (), } } |