From 6832b86aa7a9adb386394e1caaf373e65297be4e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Fri, 7 Feb 2020 06:50:18 +0000 Subject: 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. --- alacritty_terminal/src/index.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'alacritty_terminal/src/index.rs') 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 Point { #[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 + pub fn sub(mut self, num_cols: usize, rhs: usize) -> Point where - L: Copy + Add + Sub, + L: Copy + Default + Into + Add + Sub, { - 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 + pub fn add(mut self, num_cols: usize, rhs: usize) -> Point where - L: Copy + Add + Sub, + L: Add + Sub, { - 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 } } -- cgit