fix(plugin): clean up the mouse PR a little
This commit is contained in:
parent
0710594588
commit
b94b25c5fe
6 changed files with 17 additions and 15 deletions
|
|
@ -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)
|
* 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)
|
* 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)
|
* 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
|
## [0.18.1] - 2021-09-30
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ register_plugin!(State);
|
||||||
impl ZellijPlugin for State {
|
impl ZellijPlugin for State {
|
||||||
fn load(&mut self) {
|
fn load(&mut self) {
|
||||||
refresh_directory(self);
|
refresh_directory(self);
|
||||||
subscribe(&[EventType::KeyPress, EventType::Mouse]);
|
subscribe(&[EventType::Key, EventType::Mouse]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, event: Event) {
|
fn update(&mut self, event: Event) {
|
||||||
|
|
@ -21,7 +21,7 @@ impl ZellijPlugin for State {
|
||||||
};
|
};
|
||||||
self.ev_history.push_back((event.clone(), Instant::now()));
|
self.ev_history.push_back((event.clone(), Instant::now()));
|
||||||
match event {
|
match event {
|
||||||
Event::KeyPress(key) => match key {
|
Event::Key(key) => match key {
|
||||||
Key::Up | Key::Char('k') => {
|
Key::Up | Key::Char('k') => {
|
||||||
*self.selected_mut() = self.selected().saturating_sub(1);
|
*self.selected_mut() = self.selected().saturating_sub(1);
|
||||||
}
|
}
|
||||||
|
|
@ -58,12 +58,12 @@ impl ZellijPlugin for State {
|
||||||
Mouse::ScrollUp(_) => {
|
Mouse::ScrollUp(_) => {
|
||||||
*self.selected_mut() = self.selected().saturating_sub(1);
|
*self.selected_mut() = self.selected().saturating_sub(1);
|
||||||
}
|
}
|
||||||
Mouse::MouseRelease(Some((line, _))) => {
|
Mouse::Release(Some((line, _))) => {
|
||||||
if line < 0 {
|
if line < 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut should_select = true;
|
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
|
prev_event
|
||||||
{
|
{
|
||||||
if prev_line == line
|
if prev_line == line
|
||||||
|
|
@ -88,7 +88,6 @@ impl ZellijPlugin for State {
|
||||||
|
|
||||||
fn render(&mut self, rows: usize, cols: usize) {
|
fn render(&mut self, rows: usize, cols: usize) {
|
||||||
for i in 0..rows {
|
for i in 0..rows {
|
||||||
// If the key was pressed, set selected so that we can see the cursor
|
|
||||||
if self.selected() < self.scroll() {
|
if self.selected() < self.scroll() {
|
||||||
*self.scroll_mut() = self.selected();
|
*self.scroll_mut() = self.selected();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@ impl ZellijPlugin for State {
|
||||||
);
|
);
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
let mut len_cnt = 0;
|
let mut len_cnt = 0;
|
||||||
dbg!(&tab_line);
|
|
||||||
for (idx, bar_part) in tab_line.iter().enumerate() {
|
for (idx, bar_part) in tab_line.iter().enumerate() {
|
||||||
s = format!("{}{}", s, &bar_part.part);
|
s = format!("{}{}", s, &bar_part.part);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ impl Pane for PluginPane {
|
||||||
self.send_plugin_instructions
|
self.send_plugin_instructions
|
||||||
.send(PluginInstruction::Update(
|
.send(PluginInstruction::Update(
|
||||||
Some(self.pid),
|
Some(self.pid),
|
||||||
Event::Mouse(Mouse::MouseHold(position.line.0, position.column.0)),
|
Event::Mouse(Mouse::Hold(position.line.0, position.column.0)),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -294,7 +294,7 @@ impl Pane for PluginPane {
|
||||||
self.send_plugin_instructions
|
self.send_plugin_instructions
|
||||||
.send(PluginInstruction::Update(
|
.send(PluginInstruction::Update(
|
||||||
Some(self.pid),
|
Some(self.pid),
|
||||||
Event::Mouse(Mouse::MouseRelease(
|
Event::Mouse(Mouse::Release(
|
||||||
end.map(|Position { line, column }| (line.0, column.0)),
|
end.map(|Position { line, column }| (line.0, column.0)),
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
|
|
|
||||||
|
|
@ -648,7 +648,7 @@ impl Tab {
|
||||||
PaneId::Plugin(pid) => {
|
PaneId::Plugin(pid) => {
|
||||||
for key in parse_keys(&input_bytes) {
|
for key in parse_keys(&input_bytes) {
|
||||||
self.senders
|
self.senders
|
||||||
.send_to_plugin(PluginInstruction::Update(Some(pid), Event::KeyPress(key)))
|
.send_to_plugin(PluginInstruction::Update(Some(pid), Event::Key(key)))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,15 @@ pub enum Key {
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[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 {
|
pub enum Mouse {
|
||||||
ScrollUp(usize), // number of lines
|
ScrollUp(usize), // number of lines
|
||||||
ScrollDown(usize), // number of lines
|
ScrollDown(usize), // number of lines
|
||||||
LeftClick(isize, usize), // line and column
|
LeftClick(isize, usize), // line and column
|
||||||
MouseHold(isize, usize), // line and column
|
Hold(isize, usize), // line and column
|
||||||
MouseRelease(Option<(isize, usize)>), // line and column
|
Release(Option<(isize, usize)>), // line and column
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, EnumDiscriminants, ToString, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, EnumDiscriminants, ToString, Serialize, Deserialize)]
|
||||||
|
|
@ -42,7 +45,7 @@ pub enum Mouse {
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
ModeUpdate(ModeInfo),
|
ModeUpdate(ModeInfo),
|
||||||
TabUpdate(Vec<TabInfo>),
|
TabUpdate(Vec<TabInfo>),
|
||||||
KeyPress(Key),
|
Key(Key),
|
||||||
Mouse(Mouse),
|
Mouse(Mouse),
|
||||||
Timer(f64),
|
Timer(f64),
|
||||||
CopyToClipboard,
|
CopyToClipboard,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue