mirror of
https://github.com/alacritty/alacritty.git
synced 2025-02-24 16:06:43 -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:
parent
bb6a5671cb
commit
e8692c1336
2 changed files with 29 additions and 31 deletions
15
src/event.rs
15
src/event.rs
|
@ -75,10 +75,6 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
|
||||||
self.selection_modified = true;
|
self.selection_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selection_started(&self) -> bool {
|
|
||||||
self.selection.is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_selection(&mut self, point: Point, side: Side) {
|
fn update_selection(&mut self, point: Point, side: Side) {
|
||||||
self.selection_modified = true;
|
self.selection_modified = true;
|
||||||
// Update selection if one exists
|
// Update selection if one exists
|
||||||
|
@ -165,8 +161,8 @@ pub struct Mouse {
|
||||||
pub column: Column,
|
pub column: Column,
|
||||||
pub cell_side: Side,
|
pub cell_side: Side,
|
||||||
pub lines_scrolled: f32,
|
pub lines_scrolled: f32,
|
||||||
pub selection_start_pos: Point,
|
pub selection_start_point: Option<Point>,
|
||||||
pub selection_start_side: Side,
|
pub selection_start_side: Option<Side>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Mouse {
|
impl Default for Mouse {
|
||||||
|
@ -184,11 +180,8 @@ impl Default for Mouse {
|
||||||
column: Column(0),
|
column: Column(0),
|
||||||
cell_side: Side::Left,
|
cell_side: Side::Left,
|
||||||
lines_scrolled: 0.0,
|
lines_scrolled: 0.0,
|
||||||
selection_start_pos: Point {
|
selection_start_point: None,
|
||||||
line: Line(0),
|
selection_start_side: None,
|
||||||
col: Column(0),
|
|
||||||
},
|
|
||||||
selection_start_side: Side::Left,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
45
src/input.rs
45
src/input.rs
|
@ -55,7 +55,6 @@ pub trait ActionContext {
|
||||||
fn size_info(&self) -> SizeInfo;
|
fn size_info(&self) -> SizeInfo;
|
||||||
fn copy_selection(&self, Buffer);
|
fn copy_selection(&self, Buffer);
|
||||||
fn clear_selection(&mut self);
|
fn clear_selection(&mut self);
|
||||||
fn selection_started(&self) -> bool;
|
|
||||||
fn update_selection(&mut self, point: Point, side: Side);
|
fn update_selection(&mut self, point: Point, side: Side);
|
||||||
fn simple_selection(&mut self, point: Point, side: Side);
|
fn simple_selection(&mut self, point: Point, side: Side);
|
||||||
fn semantic_selection(&mut self, point: Point);
|
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)
|
|| !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 {
|
self.ctx.update_selection(Point {
|
||||||
line: point.line,
|
line: point.line,
|
||||||
col: point.col
|
col: point.col
|
||||||
}, cell_side);
|
}, 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)
|
} else if self.ctx.terminal_mode().intersects(motion_mode)
|
||||||
// Only report motion when changing cells
|
// 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) {
|
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() {
|
if let Some(point) = self.ctx.mouse_coords() {
|
||||||
self.ctx.semantic_selection(point);
|
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) {
|
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() {
|
if let Some(point) = self.ctx.mouse_coords() {
|
||||||
self.ctx.line_selection(point);
|
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
|
// Store click position for accurate selection
|
||||||
if let Some((point, side)) = self.get_mouse_pos() {
|
if let Some((point, side)) = self.get_mouse_pos() {
|
||||||
self.ctx.mouse_mut().selection_start_pos = point;
|
self.ctx.mouse_mut().selection_start_point = Some(point);
|
||||||
self.ctx.mouse_mut().selection_start_side = side;
|
self.ctx.mouse_mut().selection_start_side = Some(side);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.ctx.clear_selection();
|
self.ctx.clear_selection();
|
||||||
|
@ -706,10 +715,6 @@ mod tests {
|
||||||
// STUBBED
|
// STUBBED
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selection_started(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_selection(&mut self) {}
|
fn clear_selection(&mut self) {}
|
||||||
fn update_selection(&mut self, _point: Point, _side: Side) {}
|
fn update_selection(&mut self, _point: Point, _side: Side) {}
|
||||||
fn simple_selection(&mut self, _point: Point, _side: Side) {}
|
fn simple_selection(&mut self, _point: Point, _side: Side) {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue