1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Remove 'selection_started' method from ActionContext

By switching the start position/side of the selection to an `Option` it
was made possible to remove the `selection_started` method in favor of
checking if the two variables are `Some`.

This also renames `selection_start_pos` to `selection_start_point` to
unify the naming of variables.
This commit is contained in:
Christian Duerr 2018-06-21 23:44:24 +02:00
parent bb6a5671cb
commit e8692c1336
No known key found for this signature in database
GPG key ID: 85CDAE3C164BA7B4
2 changed files with 29 additions and 31 deletions

View file

@ -75,10 +75,6 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
self.selection_modified = true;
}
fn selection_started(&self) -> bool {
self.selection.is_some()
}
fn update_selection(&mut self, point: Point, side: Side) {
self.selection_modified = true;
// Update selection if one exists
@ -165,8 +161,8 @@ pub struct Mouse {
pub column: Column,
pub cell_side: Side,
pub lines_scrolled: f32,
pub selection_start_pos: Point,
pub selection_start_side: Side,
pub selection_start_point: Option<Point>,
pub selection_start_side: Option<Side>,
}
impl Default for Mouse {
@ -184,11 +180,8 @@ impl Default for Mouse {
column: Column(0),
cell_side: Side::Left,
lines_scrolled: 0.0,
selection_start_pos: Point {
line: Line(0),
col: Column(0),
},
selection_start_side: Side::Left,
selection_start_point: None,
selection_start_side: None,
}
}
}

View file

@ -55,7 +55,6 @@ pub trait ActionContext {
fn size_info(&self) -> SizeInfo;
fn copy_selection(&self, Buffer);
fn clear_selection(&mut self);
fn selection_started(&self) -> bool;
fn update_selection(&mut self, point: Point, side: Side);
fn simple_selection(&mut self, point: Point, side: Side);
fn semantic_selection(&mut self, point: Point);
@ -284,15 +283,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|| !self.ctx.terminal_mode().intersects(TermMode::MOUSE_REPORT_CLICK | motion_mode)
)
{
if self.ctx.selection_started() {
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 {
line: point.line,
col: point.col
}, cell_side);
} else {
let pos = self.ctx.mouse().selection_start_pos;
let side = self.ctx.mouse().selection_start_side;
self.ctx.update_selection(pos, side);
}
} else if self.ctx.terminal_mode().intersects(motion_mode)
// Only report motion when changing cells
@ -366,24 +369,30 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
}
pub fn on_mouse_double_click(&mut self) {
if self.ctx.selection_started() {
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;
self.ctx.semantic_selection(point);
} else {
if let Some(point) = self.ctx.mouse_coords() {
self.ctx.semantic_selection(point);
}
} else {
let point = self.ctx.mouse().selection_start_pos;
self.ctx.semantic_selection(point);
}
}
pub fn on_mouse_triple_click(&mut self) {
if self.ctx.selection_started() {
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;
self.ctx.line_selection(point);
} else {
if let Some(point) = self.ctx.mouse_coords() {
self.ctx.line_selection(point);
}
} else {
let point = self.ctx.mouse().selection_start_pos;
self.ctx.line_selection(point);
}
}
@ -404,8 +413,8 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
_ => {
// Store click position for accurate selection
if let Some((point, side)) = self.get_mouse_pos() {
self.ctx.mouse_mut().selection_start_pos = point;
self.ctx.mouse_mut().selection_start_side = side;
self.ctx.mouse_mut().selection_start_point = Some(point);
self.ctx.mouse_mut().selection_start_side = Some(side);
}
self.ctx.clear_selection();
@ -706,10 +715,6 @@ mod tests {
// STUBBED
}
fn selection_started(&self) -> bool {
false
}
fn clear_selection(&mut self) {}
fn update_selection(&mut self, _point: Point, _side: Side) {}
fn simple_selection(&mut self, _point: Point, _side: Side) {}