diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-06-06 13:04:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-06 13:04:12 +0000 |
commit | f15ef63edbbc5e4e685b018311e2f6424db0b0c9 (patch) | |
tree | f65bd6b6680d8654a3011d2b0b59f074dd8ab8fe /alacritty_terminal/src/term/mod.rs | |
parent | 45565bb9ca9ef33e38cf5e0592d3878e898ed325 (diff) | |
download | alacritty-f15ef63edbbc5e4e685b018311e2f6424db0b0c9.tar.gz alacritty-f15ef63edbbc5e4e685b018311e2f6424db0b0c9.zip |
Fix index out of bounds during selection
This reworks the selection logic to prevent any possible index out of
bounds exceptions by clamping the start and end points before doing
anything else with them when converting selections to spans.
This also fixes a bug where semantic selections would not automatically
expand across double-width characters.
Fixes #2486.
Diffstat (limited to 'alacritty_terminal/src/term/mod.rs')
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 629f1cbf..2ec0621a 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -189,7 +189,12 @@ impl Search for Term { impl selection::Dimensions for Term { fn dimensions(&self) -> Point { - Point { col: self.grid.num_cols(), line: self.grid.num_lines() } + let line = if self.mode.contains(TermMode::ALT_SCREEN) { + self.grid.num_lines() + } else { + Line(self.grid.len()) + }; + Point { col: self.grid.num_cols(), line } } } @@ -1062,9 +1067,8 @@ impl Term { } } - let alt_screen = self.mode.contains(TermMode::ALT_SCREEN); let selection = self.grid.selection.clone()?; - let Span { mut start, mut end } = selection.to_span(self, alt_screen)?; + let Span { mut start, mut end } = selection.to_span(self)?; let mut res = String::new(); @@ -1151,8 +1155,7 @@ impl Term { config: &'b Config, window_focused: bool, ) -> RenderableCellsIter<'_> { - let alt_screen = self.mode.contains(TermMode::ALT_SCREEN); - let selection = self.grid.selection.as_ref().and_then(|s| s.to_span(self, alt_screen)); + let selection = self.grid.selection.as_ref().and_then(|s| s.to_span(self)); let cursor = if window_focused || !config.cursor.unfocused_hollow() { self.cursor_style.unwrap_or(self.default_cursor_style) |