aboutsummaryrefslogtreecommitdiff
path: root/src/input.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2018-03-13 19:00:14 +0100
committerJoe Wilm <jwilm@users.noreply.github.com>2018-03-13 16:58:15 -0700
commit6173603677c950d96c470aa609dbc07e7d4c792f (patch)
treefebd084c4ce293e7288d9704c3f1c74f1c2dadeb /src/input.rs
parentf8e36d166342d9ee4a91f8e89f55677cd0fd0644 (diff)
downloadalacritty-6173603677c950d96c470aa609dbc07e7d4c792f.tar.gz
alacritty-6173603677c950d96c470aa609dbc07e7d4c792f.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/input.rs')
-rw-r--r--src/input.rs61
1 files changed, 30 insertions, 31 deletions
diff --git a/src/input.rs b/src/input.rs
index af45c6ef..def20b4d 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -262,44 +262,43 @@ impl From<&'static str> for Action {
impl<'a, A: ActionContext + 'a> Processor<'a, A> {
#[inline]
- pub fn mouse_moved(&mut self, x: u32, y: u32, modifiers: ModifiersState) {
+ pub fn mouse_moved(&mut self, x: usize, y: usize, modifiers: ModifiersState) {
self.ctx.mouse_mut().x = x;
self.ctx.mouse_mut().y = y;
let size_info = self.ctx.size_info();
- if let Some(point) = size_info.pixels_to_coords(x as usize, y as usize) {
- let prev_line = mem::replace(&mut self.ctx.mouse_mut().line, point.line);
- let prev_col = mem::replace(&mut self.ctx.mouse_mut().column, point.col);
+ let point = size_info.pixels_to_coords(x, y);
- let cell_x = (x as usize - size_info.padding_x as usize) % size_info.cell_width as usize;
- let half_cell_width = (size_info.cell_width / 2.0) as usize;
+ let prev_line = mem::replace(&mut self.ctx.mouse_mut().line, point.line);
+ let prev_col = mem::replace(&mut self.ctx.mouse_mut().column, point.col);
- let cell_side = if cell_x > half_cell_width
- // Edge case when mouse leaves the window
- || x as f32 >= size_info.width - size_info.padding_x
+ let cell_x = x.saturating_sub(size_info.padding_x as usize) % size_info.cell_width as usize;
+ let half_cell_width = (size_info.cell_width / 2.0) as usize;
+
+ let cell_side = if cell_x > half_cell_width
+ // Edge case when mouse leaves the window
+ || x as f32 >= size_info.width - size_info.padding_x
+ {
+ Side::Right
+ } else {
+ Side::Left
+ };
+ self.ctx.mouse_mut().cell_side = cell_side;
+
+ if self.ctx.mouse_mut().left_button_state == ElementState::Pressed {
+ let report_mode = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION;
+ if modifiers.shift || !self.ctx.terminal_mode().intersects(report_mode) {
+ self.ctx.update_selection(Point {
+ line: point.line,
+ col: point.col
+ }, cell_side);
+ } else if self.ctx.terminal_mode().contains(mode::TermMode::MOUSE_MOTION)
+ // Only report motion when changing cells
+ && (prev_line != self.ctx.mouse_mut().line
+ || prev_col != self.ctx.mouse_mut().column)
+ && size_info.contains_point(x, y)
{
- Side::Right
- } else {
- Side::Left
- };
- self.ctx.mouse_mut().cell_side = cell_side;
-
- if self.ctx.mouse_mut().left_button_state == ElementState::Pressed {
- let report_mode = mode::TermMode::MOUSE_REPORT_CLICK | mode::TermMode::MOUSE_MOTION;
- if modifiers.shift || !self.ctx.terminal_mode().intersects(report_mode) {
- self.ctx.update_selection(Point {
- line: point.line,
- col: point.col
- }, cell_side);
- } else if self.ctx.terminal_mode().contains(mode::TermMode::MOUSE_MOTION)
- // Only report motion when changing cells
- && (
- prev_line != self.ctx.mouse_mut().line
- || prev_col != self.ctx.mouse_mut().column
- )
- {
- self.mouse_report(32, ElementState::Pressed);
- }
+ self.mouse_report(32, ElementState::Pressed);
}
}
}