diff options
author | Christian Duerr <contact@christianduerr.com> | 2018-06-22 01:50:42 +0200 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2018-06-22 01:50:42 +0200 |
commit | c8fd4ff842d66d04fd0d2bdb64d994078ca40a8f (patch) | |
tree | 79c2aeb935c867f3d1955105bcb82bc30ccac18f | |
parent | e8692c1336f83acfff39400de7614ff5ac67212e (diff) | |
download | alacritty-c8fd4ff842d66d04fd0d2bdb64d994078ca40a8f.tar.gz alacritty-c8fd4ff842d66d04fd0d2bdb64d994078ca40a8f.zip |
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.
-rw-r--r-- | src/event.rs | 24 | ||||
-rw-r--r-- | src/input.rs | 24 |
2 files changed, 19 insertions, 29 deletions
diff --git a/src/event.rs b/src/event.rs index 2a4d82ec..de12d3be 100644 --- a/src/event.rs +++ b/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, diff --git a/src/input.rs b/src/input.rs index 579b1df3..fe897b2e 100644 --- a/src/input.rs +++ b/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); - } } } |