diff options
Diffstat (limited to 'zellij-client/src')
-rw-r--r-- | zellij-client/src/input_handler.rs | 68 |
1 files changed, 55 insertions, 13 deletions
diff --git a/zellij-client/src/input_handler.rs b/zellij-client/src/input_handler.rs index 7428bac0f..bebf1ee77 100644 --- a/zellij-client/src/input_handler.rs +++ b/zellij-client/src/input_handler.rs @@ -19,6 +19,19 @@ use zellij_utils::{ termwiz::input::InputEvent, }; +#[derive(Debug, Clone, Copy)] +enum HeldMouseButton { + Left, + Right, + Middle, +} + +impl Default for HeldMouseButton { + fn default() -> Self { + HeldMouseButton::Left + } +} + /// Handles the dispatching of [`Action`]s according to the current /// [`InputMode`], and keep tracks of the current [`InputMode`]. struct InputHandler { @@ -31,7 +44,7 @@ struct InputHandler { send_client_instructions: SenderWithContext<ClientInstruction>, should_exit: bool, receive_input_instructions: Receiver<(InputInstruction, ErrorContext)>, - holding_mouse: bool, + holding_mouse: Option<HeldMouseButton>, } impl InputHandler { @@ -54,7 +67,7 @@ impl InputHandler { send_client_instructions, should_exit: false, receive_input_instructions, - holding_mouse: false, + holding_mouse: None, } } @@ -161,30 +174,59 @@ impl InputHandler { self.dispatch_action(Action::ScrollDownAt(point), None); }, MouseButton::Left => { - if self.holding_mouse { - self.dispatch_action(Action::MouseHold(point), None); + if self.holding_mouse.is_some() { + self.dispatch_action(Action::MouseHoldLeft(point), None); } else { self.dispatch_action(Action::LeftClick(point), None); } - self.holding_mouse = true; + self.holding_mouse = Some(HeldMouseButton::Left); }, MouseButton::Right => { - if self.holding_mouse { - self.dispatch_action(Action::MouseHold(point), None); + if self.holding_mouse.is_some() { + self.dispatch_action(Action::MouseHoldRight(point), None); } else { self.dispatch_action(Action::RightClick(point), None); } - self.holding_mouse = true; + self.holding_mouse = Some(HeldMouseButton::Right); + }, + MouseButton::Middle => { + if self.holding_mouse.is_some() { + self.dispatch_action(Action::MouseHoldMiddle(point), None); + } else { + self.dispatch_action(Action::MiddleClick(point), None); + } + self.holding_mouse = Some(HeldMouseButton::Middle); }, - _ => {}, }, MouseEvent::Release(point) => { - self.dispatch_action(Action::MouseRelease(point), None); - self.holding_mouse = false; + let button_released = self.holding_mouse.unwrap_or_default(); + match button_released { + HeldMouseButton::Left => { + self.dispatch_action(Action::LeftMouseRelease(point), None) + }, + HeldMouseButton::Right => { + self.dispatch_action(Action::RightMouseRelease(point), None) + }, + HeldMouseButton::Middle => { + self.dispatch_action(Action::MiddleMouseRelease(point), None) + }, + }; + self.holding_mouse = None; }, MouseEvent::Hold(point) => { - self.dispatch_action(Action::MouseHold(point), None); - self.holding_mouse = true; + let button_held = self.holding_mouse.unwrap_or_default(); + match button_held { + HeldMouseButton::Left => { + self.dispatch_action(Action::MouseHoldLeft(point), None) + }, + HeldMouseButton::Right => { + self.dispatch_action(Action::MouseHoldRight(point), None) + }, + HeldMouseButton::Middle => { + self.dispatch_action(Action::MouseHoldMiddle(point), None) + }, + }; + self.holding_mouse = Some(button_held); }, } } |