diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-08-17 09:28:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 09:28:51 +0200 |
commit | f4ad946497264dbe8339f50b2e9ef0cf90a2024c (patch) | |
tree | 1a53e6f56d1a8b491457266fadc1d93f118be6b2 /zellij-client/src | |
parent | b53e3807eb682ba395a7c4f31ace42d67dca5d88 (diff) |
fix(terminal): SGR/UTF8 mouse reporting in terminal panes (#1664)
* work
* work
* fix: selection mishandling
* style(fmt): rustfmt
* style(comments): remove outdated
* style(clippy): make clippy happy
* fix(mouse): off by one sgr/utf8 reporting
* style(fmt): rustfmt
* fix(mouse): correctly report drag event code
* fix(input): support mouse middle click
* style(fmt): rustfmt
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); }, } } |