mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
Move clearing of start pos/side to event.rs
To reduce the required amount of code duplication the clearing of the selection start position and side has been moved to a helper method in the `event.rs` module which is called whenever any selection is created. Since the double and triple clicks always create a new selection without having to rely on inaccurate movement position reports, these just skip the start position/side step by setting it to `None` when the selection is created and instead use the mouse_coords() method to get the accurate mouse position.
This commit is contained in:
parent
e8692c1336
commit
c8fd4ff842
2 changed files with 19 additions and 29 deletions
24
src/event.rs
24
src/event.rs
|
@ -14,7 +14,7 @@ use config::{self, Config};
|
|||
use cli::Options;
|
||||
use display::OnResize;
|
||||
use index::{Line, Column, Side, Point};
|
||||
use input::{self, MouseBinding, KeyBinding};
|
||||
use input::{self, MouseBinding, KeyBinding, ActionContext as InputActionContext};
|
||||
use selection::Selection;
|
||||
use sync::FairMutex;
|
||||
use term::{Term, SizeInfo, TermMode};
|
||||
|
@ -88,18 +88,16 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
|
|||
}
|
||||
|
||||
fn simple_selection(&mut self, point: Point, side: Side) {
|
||||
*self.selection = Some(Selection::simple(point, side));
|
||||
self.selection_modified = true;
|
||||
self.start_selection(Selection::simple(point, side));
|
||||
}
|
||||
|
||||
fn semantic_selection(&mut self, point: Point) {
|
||||
*self.selection = Some(Selection::semantic(point, self.terminal));
|
||||
self.selection_modified = true;
|
||||
let selection = Selection::semantic(point, self.terminal);
|
||||
self.start_selection(selection);
|
||||
}
|
||||
|
||||
fn line_selection(&mut self, point: Point) {
|
||||
*self.selection = Some(Selection::lines(point));
|
||||
self.selection_modified = true;
|
||||
self.start_selection(Selection::lines(point));
|
||||
}
|
||||
|
||||
fn mouse_coords(&self) -> Option<Point> {
|
||||
|
@ -140,6 +138,18 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, N: Notify + 'a> ActionContext<'a, N> {
|
||||
/// Helper to create selections
|
||||
fn start_selection(&mut self, selection: Selection) {
|
||||
// Reset beginning of selection once selection is started
|
||||
self.mouse_mut().selection_start_point = None;
|
||||
self.mouse_mut().selection_start_side = None;
|
||||
|
||||
*self.selection = Some(selection);
|
||||
self.selection_modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ClickState {
|
||||
None,
|
||||
Click,
|
||||
|
|
24
src/input.rs
24
src/input.rs
|
@ -286,10 +286,6 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
let start_point = self.ctx.mouse().selection_start_point;
|
||||
let start_side = self.ctx.mouse().selection_start_side;
|
||||
if let (Some(point), Some(side)) = (start_point, start_side) {
|
||||
// Reset beginning of selection once selection is started
|
||||
self.ctx.mouse_mut().selection_start_point = None;
|
||||
self.ctx.mouse_mut().selection_start_side = None;
|
||||
|
||||
self.ctx.update_selection(point, side);
|
||||
} else {
|
||||
self.ctx.update_selection(Point {
|
||||
|
@ -369,30 +365,14 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
|||
}
|
||||
|
||||
pub fn on_mouse_double_click(&mut self) {
|
||||
if let Some(point) = self.ctx.mouse().selection_start_point {
|
||||
// Reset beginning of selection once selection is started
|
||||
self.ctx.mouse_mut().selection_start_point = None;
|
||||
self.ctx.mouse_mut().selection_start_side = None;
|
||||
|
||||
if let Some(point) = self.ctx.mouse_coords() {
|
||||
self.ctx.semantic_selection(point);
|
||||
} else {
|
||||
if let Some(point) = self.ctx.mouse_coords() {
|
||||
self.ctx.semantic_selection(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_mouse_triple_click(&mut self) {
|
||||
if let Some(point) = self.ctx.mouse().selection_start_point {
|
||||
// Reset beginning of selection once selection is started
|
||||
self.ctx.mouse_mut().selection_start_point = None;
|
||||
self.ctx.mouse_mut().selection_start_side = None;
|
||||
|
||||
if let Some(point) = self.ctx.mouse_coords() {
|
||||
self.ctx.line_selection(point);
|
||||
} else {
|
||||
if let Some(point) = self.ctx.mouse_coords() {
|
||||
self.ctx.line_selection(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue