diff options
author | Brooks J Rady <b.j.rady@gmail.com> | 2021-10-12 23:11:23 +0100 |
---|---|---|
committer | Brooks J Rady <b.j.rady@gmail.com> | 2021-10-12 23:11:23 +0100 |
commit | b94b25c5fe504eb9f9f15cfebaa7cb5f9c0af2e6 (patch) | |
tree | 00e876635601ff2fb928ad4aa74d26f11c4afaf1 | |
parent | 0710594588aa768b934f925704dc57486dc0a157 (diff) |
fix(plugin): clean up the mouse PR a little
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | default-plugins/strider/src/main.rs | 9 | ||||
-rw-r--r-- | default-plugins/tab-bar/src/main.rs | 1 | ||||
-rw-r--r-- | zellij-server/src/panes/plugin_pane.rs | 4 | ||||
-rw-r--r-- | zellij-server/src/tab.rs | 2 | ||||
-rw-r--r-- | zellij-tile/src/data.rs | 15 |
6 files changed, 17 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a172237da..4f48b1f0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Refactor: handle clients in tabs/screen (https://github.com/zellij-org/zellij/pull/770) * Feature: kill-session and kill-all-sessions cli commands (https://github.com/zellij-org/zellij/pull/745) * Fix: Keep default file permissions for new files (https://github.com/zellij-org/zellij/pull/777) +* Feature: Add mouse events to plugins – including strider and the tab-bar (https://github.com/zellij-org/zellij/pull/629) ## [0.18.1] - 2021-09-30 diff --git a/default-plugins/strider/src/main.rs b/default-plugins/strider/src/main.rs index 3bdceefdd..4aca9354e 100644 --- a/default-plugins/strider/src/main.rs +++ b/default-plugins/strider/src/main.rs @@ -10,7 +10,7 @@ register_plugin!(State); impl ZellijPlugin for State { fn load(&mut self) { refresh_directory(self); - subscribe(&[EventType::KeyPress, EventType::Mouse]); + subscribe(&[EventType::Key, EventType::Mouse]); } fn update(&mut self, event: Event) { @@ -21,7 +21,7 @@ impl ZellijPlugin for State { }; self.ev_history.push_back((event.clone(), Instant::now())); match event { - Event::KeyPress(key) => match key { + Event::Key(key) => match key { Key::Up | Key::Char('k') => { *self.selected_mut() = self.selected().saturating_sub(1); } @@ -58,12 +58,12 @@ impl ZellijPlugin for State { Mouse::ScrollUp(_) => { *self.selected_mut() = self.selected().saturating_sub(1); } - Mouse::MouseRelease(Some((line, _))) => { + Mouse::Release(Some((line, _))) => { if line < 0 { return; } let mut should_select = true; - if let Some((Event::Mouse(Mouse::MouseRelease(Some((prev_line, _)))), t)) = + if let Some((Event::Mouse(Mouse::Release(Some((prev_line, _)))), t)) = prev_event { if prev_line == line @@ -88,7 +88,6 @@ impl ZellijPlugin for State { fn render(&mut self, rows: usize, cols: usize) { for i in 0..rows { - // If the key was pressed, set selected so that we can see the cursor if self.selected() < self.scroll() { *self.scroll_mut() = self.selected(); } diff --git a/default-plugins/tab-bar/src/main.rs b/default-plugins/tab-bar/src/main.rs index c34693523..936c18e48 100644 --- a/default-plugins/tab-bar/src/main.rs +++ b/default-plugins/tab-bar/src/main.rs @@ -98,7 +98,6 @@ impl ZellijPlugin for State { ); let mut s = String::new(); let mut len_cnt = 0; - dbg!(&tab_line); for (idx, bar_part) in tab_line.iter().enumerate() { s = format!("{}{}", s, &bar_part.part); diff --git a/zellij-server/src/panes/plugin_pane.rs b/zellij-server/src/panes/plugin_pane.rs index f58d9f738..8659ae155 100644 --- a/zellij-server/src/panes/plugin_pane.rs +++ b/zellij-server/src/panes/plugin_pane.rs @@ -286,7 +286,7 @@ impl Pane for PluginPane { self.send_plugin_instructions .send(PluginInstruction::Update( Some(self.pid), - Event::Mouse(Mouse::MouseHold(position.line.0, position.column.0)), + Event::Mouse(Mouse::Hold(position.line.0, position.column.0)), )) .unwrap(); } @@ -294,7 +294,7 @@ impl Pane for PluginPane { self.send_plugin_instructions .send(PluginInstruction::Update( Some(self.pid), - Event::Mouse(Mouse::MouseRelease( + Event::Mouse(Mouse::Release( end.map(|Position { line, column }| (line.0, column.0)), )), )) diff --git a/zellij-server/src/tab.rs b/zellij-server/src/tab.rs index 2b966d760..81372fdf2 100644 --- a/zellij-server/src/tab.rs +++ b/zellij-server/src/tab.rs @@ -648,7 +648,7 @@ impl Tab { PaneId::Plugin(pid) => { for key in parse_keys(&input_bytes) { self.senders - .send_to_plugin(PluginInstruction::Update(Some(pid), Event::KeyPress(key))) + .send_to_plugin(PluginInstruction::Update(Some(pid), Event::Key(key))) .unwrap() } } diff --git a/zellij-tile/src/data.rs b/zellij-tile/src/data.rs index c98ebb248..4d6bba303 100644 --- a/zellij-tile/src/data.rs +++ b/zellij-tile/src/data.rs @@ -27,12 +27,15 @@ pub enum Key { #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +// FIXME: This should be extended to handle different button clicks (not just +// left click) and the `ScrollUp` and `ScrollDown` events could probably be +// merged into a single `Scroll(isize)` event. pub enum Mouse { - ScrollUp(usize), // number of lines - ScrollDown(usize), // number of lines - LeftClick(isize, usize), // line and column - MouseHold(isize, usize), // line and column - MouseRelease(Option<(isize, usize)>), // line and column + ScrollUp(usize), // number of lines + ScrollDown(usize), // number of lines + LeftClick(isize, usize), // line and column + Hold(isize, usize), // line and column + Release(Option<(isize, usize)>), // line and column } #[derive(Debug, Clone, PartialEq, EnumDiscriminants, ToString, Serialize, Deserialize)] @@ -42,7 +45,7 @@ pub enum Mouse { pub enum Event { ModeUpdate(ModeInfo), TabUpdate(Vec<TabInfo>), - KeyPress(Key), + Key(Key), Mouse(Mouse), Timer(f64), CopyToClipboard, |