diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-03-13 19:00:14 +0100 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2018-06-02 09:56:50 -0700 |
commit | 58c69cafad3b1dafa3631d911c6bfc21f5e5dec5 (patch) | |
tree | 73aea66e64622357685600197a9e14c30889f51d /src/term | |
parent | d9bd21d33f7f35d1362a581cefb1c897a821fcad (diff) | |
download | alacritty-58c69cafad3b1dafa3631d911c6bfc21f5e5dec5.tar.gz alacritty-58c69cafad3b1dafa3631d911c6bfc21f5e5dec5.zip |
Fix multi-line selection with single cell end
When the user selected multiple lines, dragging the selection downwards,
and then leaves the cursor to the left side of the first cell, the first
cell was still incorrectly selected. This has been fixed.
The selection also did not update if the mouse was outside of the
window, now all movement events are accpeted even when the mouse is
outside of the window. This allows updating the selection when the user
is dragging the cursor too far.
Mouse movement and click events outside of the window are not
propagated, these are only used for updating the selection.
Diffstat (limited to 'src/term')
-rw-r--r-- | src/term/mod.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs index 6318c680..8db21402 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -791,25 +791,21 @@ impl SizeInfo { Column(((self.width - 2. * self.padding_x) / self.cell_width) as usize) } - fn contains_point(&self, x: usize, y:usize) -> bool { + pub fn contains_point(&self, x: usize, y:usize) -> bool { x <= (self.width - self.padding_x) as usize && x >= self.padding_x as usize && y <= (self.height - self.padding_y) as usize && y >= self.padding_y as usize } - pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<Point> { - if !self.contains_point(x, y) { - return None; - } + pub fn pixels_to_coords(&self, x: usize, y: usize) -> Point { + let col = Column(x.saturating_sub(self.padding_x as usize) / (self.cell_width as usize)); + let line = Line(y.saturating_sub(self.padding_y as usize) / (self.cell_height as usize)); - let col = Column((x - self.padding_x as usize) / (self.cell_width as usize)); - let line = Line((y - self.padding_y as usize) / (self.cell_height as usize)); - - Some(Point { + Point { line: min(line, self.lines() - 1), col: min(col, self.cols() - 1) - }) + } } } @@ -1036,7 +1032,11 @@ impl Term { /// /// Returns None if the coordinates are outside the screen pub fn pixels_to_coords(&self, x: usize, y: usize) -> Option<Point> { - self.size_info().pixels_to_coords(x, y) + if self.size_info.contains_point(x, y) { + Some(self.size_info.pixels_to_coords(x, y)) + } else { + None + } } /// Access to the raw grid data structure |