diff options
Diffstat (limited to 'src/input.rs')
-rw-r--r-- | src/input.rs | 61 |
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); } } } |