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 { @@ -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); - } } }