Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins): send events to plugins properly in a multiuser env #986

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,50 +306,51 @@ impl Pane for PluginPane {
self.geom.y -= count;
self.should_render = true;
}
fn scroll_up(&mut self, count: usize) {
fn scroll_up(&mut self, count: usize, client_id: ClientId) {
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::ScrollUp(count)),
))
.unwrap();
}
fn scroll_down(&mut self, count: usize) {
fn scroll_down(&mut self, count: usize, client_id: ClientId) {
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::ScrollDown(count)),
))
.unwrap();
}
fn clear_scroll(&mut self) {
unimplemented!();
}
fn start_selection(&mut self, start: &Position) {
fn start_selection(&mut self, start: &Position, client_id: ClientId) {
log::info!("plugin pane send left click plugin instruction");
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::LeftClick(start.line.0, start.column.0)),
))
.unwrap();
}
fn update_selection(&mut self, position: &Position) {
fn update_selection(&mut self, position: &Position, client_id: ClientId) {
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::Hold(position.line.0, position.column.0)),
))
.unwrap();
}
fn end_selection(&mut self, end: Option<&Position>) {
fn end_selection(&mut self, end: Option<&Position>, client_id: ClientId) {
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::Release(
end.map(|Position { line, column }| (line.0, column.0)),
)),
Expand Down Expand Up @@ -379,11 +380,11 @@ impl Pane for PluginPane {
fn borderless(&self) -> bool {
self.borderless
}
fn handle_right_click(&mut self, to: &Position) {
fn handle_right_click(&mut self, to: &Position, client_id: ClientId) {
self.send_plugin_instructions
.send(PluginInstruction::Update(
Some(self.pid),
None,
Some(client_id),
Event::Mouse(Mouse::RightClick(to.line.0, to.column.0)),
))
.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,11 @@ impl Pane for TerminalPane {
self.geom.y -= count;
self.reflow_lines();
}
fn scroll_up(&mut self, count: usize) {
fn scroll_up(&mut self, count: usize, _client_id: ClientId) {
self.grid.move_viewport_up(count);
self.set_should_render(true);
}
fn scroll_down(&mut self, count: usize) {
fn scroll_down(&mut self, count: usize, _client_id: ClientId) {
self.grid.move_viewport_down(count);
self.set_should_render(true);
}
Expand Down Expand Up @@ -452,12 +452,12 @@ impl Pane for TerminalPane {
self.grid.pending_messages_to_pty.drain(..).collect()
}

fn start_selection(&mut self, start: &Position) {
fn start_selection(&mut self, start: &Position, client_id: ClientId) {
self.grid.start_selection(start);
self.set_should_render(true);
}

fn update_selection(&mut self, to: &Position) {
fn update_selection(&mut self, to: &Position, _client_id: ClientId) {
let should_scroll = self.selection_scrolled_at.elapsed()
>= time::Duration::from_millis(SELECTION_SCROLL_INTERVAL_MS);
// TODO: check how far up/down mouse is relative to pane, to increase scroll lines?
Expand All @@ -474,7 +474,7 @@ impl Pane for TerminalPane {
self.set_should_render(true);
}

fn end_selection(&mut self, end: Option<&Position>) {
fn end_selection(&mut self, end: Option<&Position>, _client_id: ClientId) {
self.grid.end_selection(end);
self.set_should_render(true);
}
Expand Down
5 changes: 3 additions & 2 deletions zellij-server/src/panes/unit/terminal_pane_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::fmt::Write;

#[test]
pub fn scrolling_inside_a_pane() {
let fake_client_id = 1;
let mut fake_win_size = PaneGeom::default();
fake_win_size.cols.set_inner(121);
fake_win_size.rows.set_inner(20);
Expand All @@ -20,9 +21,9 @@ pub fn scrolling_inside_a_pane() {
writeln!(&mut text_to_fill_pane, "\rline {}", i + 1).unwrap();
}
terminal_pane.handle_pty_bytes(text_to_fill_pane.into_bytes());
terminal_pane.scroll_up(10);
terminal_pane.scroll_up(10, fake_client_id);
assert_snapshot!(format!("{:?}", terminal_pane.grid));
terminal_pane.scroll_down(3);
terminal_pane.scroll_down(3, fake_client_id);
assert_snapshot!(format!("{:?}", terminal_pane.grid));
terminal_pane.clear_scroll();
assert_snapshot!(format!("{:?}", terminal_pane.grid));
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ pub(crate) fn screen_thread_main(
screen
.get_active_tab_mut(client_id)
.unwrap()
.scroll_terminal_up(&point, 3);
.scroll_terminal_up(&point, 3, client_id);

screen.render();
}
Expand All @@ -947,7 +947,7 @@ pub(crate) fn screen_thread_main(
screen
.get_active_tab_mut(client_id)
.unwrap()
.scroll_terminal_down(&point, 3);
.scroll_terminal_down(&point, 3, client_id);

screen.render();
}
Expand Down
42 changes: 21 additions & 21 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ pub trait Pane {
fn push_right(&mut self, count: usize);
fn pull_left(&mut self, count: usize);
fn pull_up(&mut self, count: usize);
fn scroll_up(&mut self, count: usize);
fn scroll_down(&mut self, count: usize);
fn scroll_up(&mut self, count: usize, client_id: ClientId);
fn scroll_down(&mut self, count: usize, client_id: ClientId);
fn clear_scroll(&mut self);
fn is_scrolled(&self) -> bool;
fn active_at(&self) -> Instant;
Expand All @@ -194,9 +194,9 @@ pub trait Pane {
None => self.position_and_size().contains(position),
}
}
fn start_selection(&mut self, _start: &Position) {}
fn update_selection(&mut self, _position: &Position) {}
fn end_selection(&mut self, _end: Option<&Position>) {}
fn start_selection(&mut self, _start: &Position, _client_id: ClientId) {}
fn update_selection(&mut self, _position: &Position, _client_id: ClientId) {}
fn end_selection(&mut self, _end: Option<&Position>, _client_id: ClientId) {}
fn reset_selection(&mut self) {}
fn get_selected_text(&self) -> Option<String> {
None
Expand Down Expand Up @@ -265,7 +265,7 @@ pub trait Pane {
}
fn set_borderless(&mut self, borderless: bool);
fn borderless(&self) -> bool;
fn handle_right_click(&mut self, _to: &Position) {}
fn handle_right_click(&mut self, _to: &Position, _client_id: ClientId) {}
}

macro_rules! resize_pty {
Expand Down Expand Up @@ -1696,7 +1696,7 @@ impl Tab {
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
active_terminal.scroll_up(1);
active_terminal.scroll_up(1, client_id);
}
}
pub fn scroll_active_terminal_down(&mut self, client_id: ClientId) {
Expand All @@ -1705,7 +1705,7 @@ impl Tab {
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
active_terminal.scroll_down(1);
active_terminal.scroll_down(1, client_id);
if !active_terminal.is_scrolled() {
self.process_pending_vte_events(active_terminal_id);
}
Expand All @@ -1719,7 +1719,7 @@ impl Tab {
.unwrap();
// prevent overflow when row == 0
let scroll_rows = active_terminal.rows().max(1) - 1;
active_terminal.scroll_up(scroll_rows);
active_terminal.scroll_up(scroll_rows, client_id);
}
}
pub fn scroll_active_terminal_down_page(&mut self, client_id: ClientId) {
Expand All @@ -1730,7 +1730,7 @@ impl Tab {
.unwrap();
// prevent overflow when row == 0
let scroll_rows = active_terminal.rows().max(1) - 1;
active_terminal.scroll_down(scroll_rows);
active_terminal.scroll_down(scroll_rows, client_id);
if !active_terminal.is_scrolled() {
self.process_pending_vte_events(active_terminal_id);
}
Expand All @@ -1744,7 +1744,7 @@ impl Tab {
.unwrap();
// prevent overflow when row == 0
let scroll_rows = (active_terminal.rows().max(1) - 1) / 2;
active_terminal.scroll_up(scroll_rows);
active_terminal.scroll_up(scroll_rows, client_id);
}
}
pub fn scroll_active_terminal_down_half_page(&mut self, client_id: ClientId) {
Expand All @@ -1755,7 +1755,7 @@ impl Tab {
.unwrap();
// prevent overflow when row == 0
let scroll_rows = (active_terminal.rows().max(1) - 1) / 2;
active_terminal.scroll_down(scroll_rows);
active_terminal.scroll_down(scroll_rows, client_id);
if !active_terminal.is_scrolled() {
self.process_pending_vte_events(active_terminal_id);
}
Expand Down Expand Up @@ -1785,14 +1785,14 @@ impl Tab {
}
}
}
pub fn scroll_terminal_up(&mut self, point: &Position, lines: usize) {
pub fn scroll_terminal_up(&mut self, point: &Position, lines: usize, client_id: ClientId) {
if let Some(pane) = self.get_pane_at(point, false) {
pane.scroll_up(lines);
pane.scroll_up(lines, client_id);
}
}
pub fn scroll_terminal_down(&mut self, point: &Position, lines: usize) {
pub fn scroll_terminal_down(&mut self, point: &Position, lines: usize, client_id: ClientId) {
if let Some(pane) = self.get_pane_at(point, false) {
pane.scroll_down(lines);
pane.scroll_down(lines, client_id);
if !pane.is_scrolled() {
if let PaneId::Terminal(pid) = pane.pid() {
self.process_pending_vte_events(pid);
Expand Down Expand Up @@ -1832,7 +1832,7 @@ impl Tab {

if let Some(pane) = self.get_pane_at(position, false) {
let relative_position = pane.relative_position(position);
pane.start_selection(&relative_position);
pane.start_selection(&relative_position, client_id);
self.selecting_with_mouse = true;
};
}
Expand All @@ -1841,7 +1841,7 @@ impl Tab {

if let Some(pane) = self.get_pane_at(position, false) {
let relative_position = pane.relative_position(position);
pane.handle_right_click(&relative_position);
pane.handle_right_click(&relative_position, client_id);
};
}
fn focus_pane_at(&mut self, point: &Position, client_id: ClientId) {
Expand Down Expand Up @@ -1869,14 +1869,14 @@ impl Tab {
if active_pane_id != self.get_pane_id_at(position, true) {
if let Some(active_pane_id) = active_pane_id {
if let Some(active_pane) = self.panes.get_mut(&active_pane_id) {
active_pane.end_selection(None);
active_pane.end_selection(None, client_id);
selected_text = active_pane.get_selected_text();
active_pane.reset_selection();
}
}
} else if let Some(pane) = self.get_pane_at(position, true) {
let relative_position = pane.relative_position(position);
pane.end_selection(Some(&relative_position));
pane.end_selection(Some(&relative_position), client_id);
selected_text = pane.get_selected_text();
pane.reset_selection();
}
Expand All @@ -1890,7 +1890,7 @@ impl Tab {
if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
if let Some(active_pane) = self.panes.get_mut(&active_pane_id) {
let relative_position = active_pane.relative_position(position_on_screen);
active_pane.update_selection(&relative_position);
active_pane.update_selection(&relative_position, client_id);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion zellij-server/src/wasm_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ pub(crate) fn wasm_thread_main(
if subs.contains(&event_type)
&& ((pid.is_none() && cid.is_none())
|| (pid.is_none() && cid == Some(client_id))
|| (cid.is_none() && pid == Some(plugin_id)))
|| (cid.is_none() && pid == Some(plugin_id))
|| (cid == Some(client_id) && pid == Some(plugin_id)))
{
let update = instance.exports.get_function("update").unwrap();
wasi_write_object(&plugin_env.wasi_env, &event);
Expand Down