aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/input.rs
diff options
context:
space:
mode:
authorJason Heard <jasonh@pandell.com>2021-07-29 09:40:51 -0600
committerGitHub <noreply@github.com>2021-07-29 15:40:51 +0000
commit3c309a0953566fe6f726b84eb117fd9cfa42df3d (patch)
treed6f4c6200bc4f9a6abb192adeee5bb15b4603815 /alacritty/src/input.rs
parent96a098c358870e8be41921f19ed72810651106ae (diff)
downloadr-alacritty-3c309a0953566fe6f726b84eb117fd9cfa42df3d.tar.gz
r-alacritty-3c309a0953566fe6f726b84eb117fd9cfa42df3d.tar.bz2
r-alacritty-3c309a0953566fe6f726b84eb117fd9cfa42df3d.zip
Add ExpandSelection mouse binding action
Fixes #4132.
Diffstat (limited to 'alacritty/src/input.rs')
-rw-r--r--alacritty/src/input.rs53
1 files changed, 9 insertions, 44 deletions
diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs
index 3258137c..98a1b723 100644
--- a/alacritty/src/input.rs
+++ b/alacritty/src/input.rs
@@ -29,7 +29,7 @@ use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
use alacritty_terminal::vi_mode::ViMotion;
use crate::clipboard::Clipboard;
-use crate::config::{Action, BindingMode, Config, Key, SearchAction, ViAction};
+use crate::config::{Action, BindingMode, Config, Key, MouseAction, SearchAction, ViAction};
use crate::daemon::start_daemon;
use crate::display::hint::HintMatch;
use crate::display::window::Window;
@@ -104,6 +104,7 @@ pub trait ActionContext<T: EventListener> {
fn toggle_vi_mode(&mut self) {}
fn hint_input(&mut self, _character: char) {}
fn trigger_hint(&mut self, _hint: &HintMatch) {}
+ fn expand_selection(&mut self) {}
fn paste(&mut self, _text: &str) {}
}
@@ -231,6 +232,7 @@ impl<T: EventListener> Execute<T> for Action {
Action::Search(SearchAction::SearchDeleteWord) => ctx.search_pop_word(),
Action::Search(SearchAction::SearchHistoryPrevious) => ctx.search_history_previous(),
Action::Search(SearchAction::SearchHistoryNext) => ctx.search_history_next(),
+ Action::Mouse(MouseAction::ExpandSelection) => ctx.expand_selection(),
Action::SearchForward => ctx.start_search(Direction::Right),
Action::SearchBackward => ctx.start_search(Direction::Left),
Action::Copy => ctx.copy_selection(ClipboardType::Clipboard),
@@ -531,51 +533,12 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
let display_offset = self.ctx.terminal().grid().display_offset();
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
- match button {
- MouseButton::Left => self.on_left_click(point),
- MouseButton::Right => self.on_right_click(point),
- // Do nothing when using buttons other than LMB.
- _ => self.ctx.mouse_mut().click_state = ClickState::None,
+ if let MouseButton::Left = button {
+ self.on_left_click(point)
}
}
}
- /// Handle selection expansion on right click.
- fn on_right_click(&mut self, point: Point) {
- match self.ctx.mouse().click_state {
- ClickState::Click => {
- let selection_type = if self.ctx.modifiers().ctrl() {
- SelectionType::Block
- } else {
- SelectionType::Simple
- };
-
- self.expand_selection(point, selection_type);
- },
- ClickState::DoubleClick => self.expand_selection(point, SelectionType::Semantic),
- ClickState::TripleClick => self.expand_selection(point, SelectionType::Lines),
- ClickState::None => (),
- }
- }
-
- /// Expand existing selection.
- fn expand_selection(&mut self, point: Point, selection_type: SelectionType) {
- let cell_side = self.ctx.mouse().cell_side;
-
- let selection = match &mut self.ctx.terminal_mut().selection {
- Some(selection) => selection,
- None => return,
- };
-
- selection.ty = selection_type;
- self.ctx.update_selection(point, cell_side);
-
- // Move vi mode cursor to mouse click position.
- if self.ctx.terminal().mode().contains(TermMode::VI) && !self.ctx.search_active() {
- self.ctx.terminal_mut().vi_mode_cursor.point = point;
- }
- }
-
/// Handle left click selection and vi mode cursor movement.
fn on_left_click(&mut self, point: Point) {
let side = self.ctx.mouse().cell_side;
@@ -749,8 +712,9 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
} else {
match state {
ElementState::Pressed => {
- self.process_mouse_bindings(button);
+ // Process mouse press before bindings to update the `click_state`.
self.on_mouse_press(button);
+ self.process_mouse_bindings(button);
},
ElementState::Released => self.on_mouse_release(button),
}
@@ -1138,6 +1102,7 @@ mod tests {
let mut mouse = Mouse {
click_state: $initial_state,
+ last_click_button: $initial_button,
..Mouse::default()
};
@@ -1239,7 +1204,7 @@ mod tests {
},
window_id: unsafe { std::mem::transmute_copy(&0) },
},
- end_state: ClickState::None,
+ end_state: ClickState::Click,
}
test_clickstate! {