From 3c309a0953566fe6f726b84eb117fd9cfa42df3d Mon Sep 17 00:00:00 2001 From: Jason Heard Date: Thu, 29 Jul 2021 09:40:51 -0600 Subject: Add ExpandSelection mouse binding action Fixes #4132. --- alacritty/src/config/bindings.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'alacritty/src/config/bindings.rs') diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index 57237ad3..a4271430 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -109,6 +109,10 @@ pub enum Action { #[config(skip)] Search(SearchAction), + /// Perform mouse binding exclusive action. + #[config(skip)] + Mouse(MouseAction), + /// Paste contents of system clipboard. Paste, @@ -227,12 +231,19 @@ impl From for Action { } } +impl From for Action { + fn from(action: MouseAction) -> Self { + Self::Mouse(action) + } +} + /// Display trait used for error logging. impl Display for Action { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Action::ViMotion(motion) => motion.fmt(f), Action::Vi(action) => action.fmt(f), + Action::Mouse(action) => action.fmt(f), _ => write!(f, "{:?}", self), } } @@ -283,6 +294,13 @@ pub enum SearchAction { SearchHistoryNext, } +/// Mouse binding specific actions. +#[derive(ConfigDeserialize, Debug, Copy, Clone, PartialEq, Eq)] +pub enum MouseAction { + /// Expand the selection to the current mouse cursor position. + ExpandSelection, +} + macro_rules! bindings { ( KeyBinding; @@ -343,6 +361,7 @@ macro_rules! bindings { pub fn default_mouse_bindings() -> Vec { bindings!( MouseBinding; + MouseButton::Right; MouseAction::ExpandSelection; MouseButton::Middle, ~BindingMode::VI; Action::PasteSelection; ) } @@ -1027,6 +1046,9 @@ impl<'a> Deserialize<'a> for RawBinding { SearchAction::deserialize(value.clone()) { Some(search_action.into()) + } else if let Ok(mouse_action) = MouseAction::deserialize(value.clone()) + { + Some(mouse_action.into()) } else { match Action::deserialize(value.clone()).map_err(V::Error::custom) { Ok(action) => Some(action), @@ -1102,6 +1124,15 @@ impl<'a> Deserialize<'a> for RawBinding { } action }, + (Some(action @ Action::Mouse(_)), None, None) => { + if mouse.is_none() { + return Err(V::Error::custom(format!( + "action `{}` is only available for mouse bindings", + action, + ))); + } + action + }, (Some(action), None, None) => action, (None, Some(chars), None) => Action::Esc(chars), (None, None, Some(cmd)) => Action::Command(cmd), -- cgit