diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-02-07 06:50:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 09:50:18 +0300 |
commit | 6832b86aa7a9adb386394e1caaf373e65297be4e (patch) | |
tree | b320ab78e8ad64305dee6e765799c4f7d0de7dce /alacritty_terminal/src/index.rs | |
parent | cbec5e415b721e5d5a8359ebed247ac39eb99721 (diff) | |
download | alacritty-6832b86aa7a9adb386394e1caaf373e65297be4e.tar.gz alacritty-6832b86aa7a9adb386394e1caaf373e65297be4e.zip |
Fix selection expansion across full-width glyphs
Instead of trying to expand the start and end of a selection across
full-width glyphs, the selection should now only go from its origin to
the end without any kind of expansion.
Instead, the expansion is now done where the cells are actually checked
for their selection status, expanding across the entire full-width glyph
whenever any part of it is selected.
Fixes #3106.
Diffstat (limited to 'alacritty_terminal/src/index.rs')
-rw-r--r-- | alacritty_terminal/src/index.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/alacritty_terminal/src/index.rs b/alacritty_terminal/src/index.rs index fb21baa0..51566d8d 100644 --- a/alacritty_terminal/src/index.rs +++ b/alacritty_terminal/src/index.rs @@ -44,33 +44,29 @@ impl<L> Point<L> { #[inline] #[must_use = "this returns the result of the operation, without modifying the original"] - pub fn sub(mut self, num_cols: usize, length: usize, absolute_indexing: bool) -> Point<L> + pub fn sub(mut self, num_cols: usize, rhs: usize) -> Point<L> where - L: Copy + Add<usize, Output = L> + Sub<usize, Output = L>, + L: Copy + Default + Into<Line> + Add<usize, Output = L> + Sub<usize, Output = L>, { - let line_changes = f32::ceil(length.saturating_sub(self.col.0) as f32 / num_cols as f32); - if absolute_indexing { - self.line = self.line + line_changes as usize; + let line_changes = + f32::ceil(rhs.saturating_sub(self.col.0) as f32 / num_cols as f32) as usize; + if self.line.into() > Line(line_changes) { + self.line = self.line - line_changes; } else { - self.line = self.line - line_changes as usize; + self.line = Default::default(); } - self.col = Column((num_cols + self.col.0 - length % num_cols) % num_cols); + self.col = Column((num_cols + self.col.0 - rhs % num_cols) % num_cols); self } #[inline] #[must_use = "this returns the result of the operation, without modifying the original"] - pub fn add(mut self, num_cols: usize, length: usize, absolute_indexing: bool) -> Point<L> + pub fn add(mut self, num_cols: usize, rhs: usize) -> Point<L> where - L: Copy + Add<usize, Output = L> + Sub<usize, Output = L>, + L: Add<usize, Output = L> + Sub<usize, Output = L>, { - let line_changes = (length + self.col.0) / num_cols; - if absolute_indexing { - self.line = self.line - line_changes; - } else { - self.line = self.line + line_changes; - } - self.col = Column((self.col.0 + length) % num_cols); + self.line = self.line + (rhs + self.col.0) / num_cols; + self.col = Column((self.col.0 + rhs) % num_cols); self } } |