summaryrefslogtreecommitdiffstats
path: root/zellij-server
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-04-04 18:39:34 +0200
committerGitHub <noreply@github.com>2023-04-04 18:39:34 +0200
commitf5a13c7440b422d8aef3eb436abf11f39a33d9b7 (patch)
treef42dd6dfc5651b1d680c38490163041f1fb7c17f /zellij-server
parent9d4e60e323a98a523792acc282ab54414e6b17d8 (diff)
fix(plugins): prevent Strider from opening double-panes when editing files (#2346)
* fix(plugins): make sure to include client_id when writing input * style(fmt): rustfmt * fix(plugins): do not remove client plugins on detach
Diffstat (limited to 'zellij-server')
-rw-r--r--zellij-server/src/screen.rs2
-rw-r--r--zellij-server/src/tab/mod.rs34
-rw-r--r--zellij-server/src/tab/unit/tab_tests.rs2
3 files changed, 24 insertions, 14 deletions
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 380b124be..ecd1c7521 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -1664,7 +1664,7 @@ pub(crate) fn screen_thread_main(
client_id,
|tab: &mut Tab, client_id: ClientId| {
let write_result = match tab.is_sync_panes_active() {
- true => tab.write_to_terminals_on_current_tab(bytes),
+ true => tab.write_to_terminals_on_current_tab(bytes, client_id),
false => tab.write_to_active_terminal(bytes, client_id),
};
if let Ok(true) = write_result {
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index eab71da9c..d61eb1a4c 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -1550,7 +1550,7 @@ impl Tab {
let messages_to_pty = terminal_output.drain_messages_to_pty();
let clipboard_update = terminal_output.drain_clipboard_update();
for message in messages_to_pty {
- self.write_to_pane_id(message, PaneId::Terminal(pid))
+ self.write_to_pane_id(message, PaneId::Terminal(pid), None)
.with_context(err_context)?;
}
if let Some(string) = clipboard_update {
@@ -1561,14 +1561,18 @@ impl Tab {
Ok(())
}
- pub fn write_to_terminals_on_current_tab(&mut self, input_bytes: Vec<u8>) -> Result<bool> {
+ pub fn write_to_terminals_on_current_tab(
+ &mut self,
+ input_bytes: Vec<u8>,
+ client_id: ClientId,
+ ) -> Result<bool> {
// returns true if a UI update should be triggered (eg. when closing a command pane with
// ctrl-c)
let mut should_trigger_ui_change = false;
let pane_ids = self.get_static_and_floating_pane_ids();
for pane_id in pane_ids {
let ui_change_triggered = self
- .write_to_pane_id(input_bytes.clone(), pane_id)
+ .write_to_pane_id(input_bytes.clone(), pane_id, Some(client_id))
.context("failed to write to terminals on current tab")?;
if ui_change_triggered {
should_trigger_ui_change = true;
@@ -1607,7 +1611,7 @@ impl Tab {
.with_context(err_context)?
};
// Can't use 'err_context' here since it borrows 'input_bytes'
- self.write_to_pane_id(input_bytes, pane_id)
+ self.write_to_pane_id(input_bytes, pane_id, Some(client_id))
.with_context(|| format!("failed to write to active terminal for client {client_id}"))
}
@@ -1615,6 +1619,7 @@ impl Tab {
&mut self,
input_bytes: Vec<u8>,
position: &Position,
+ client_id: ClientId,
) -> Result<()> {
let err_context = || format!("failed to write to terminal at position {position:?}");
@@ -1624,7 +1629,7 @@ impl Tab {
.get_pane_id_at(position, false)
.with_context(err_context)?;
if let Some(pane_id) = pane_id {
- self.write_to_pane_id(input_bytes, pane_id)
+ self.write_to_pane_id(input_bytes, pane_id, Some(client_id))
.with_context(err_context)?;
return Ok(());
}
@@ -1634,14 +1639,19 @@ impl Tab {
.get_pane_id_at(position, false)
.with_context(err_context)?;
if let Some(pane_id) = pane_id {
- self.write_to_pane_id(input_bytes, pane_id)
+ self.write_to_pane_id(input_bytes, pane_id, Some(client_id))
.with_context(err_context)?;
return Ok(());
}
Ok(())
}
- pub fn write_to_pane_id(&mut self, input_bytes: Vec<u8>, pane_id: PaneId) -> Result<bool> {
+ pub fn write_to_pane_id(
+ &mut self,
+ input_bytes: Vec<u8>,
+ pane_id: PaneId,
+ client_id: Option<ClientId>,
+ ) -> Result<bool> {
// returns true if we need to update the UI (eg. when a command pane is closed with ctrl-c)
let err_context = || format!("failed to write to pane with id {pane_id:?}");
@@ -1683,7 +1693,7 @@ impl Tab {
PaneId::Plugin(pid) => {
let mut plugin_updates = vec![];
for key in parse_keys(&input_bytes) {
- plugin_updates.push((Some(pid), None, Event::Key(key)));
+ plugin_updates.push((Some(pid), client_id, Event::Key(key)));
}
self.senders
.send_to_plugin(PluginInstruction::Update(plugin_updates))
@@ -2592,13 +2602,13 @@ impl Tab {
if let Some(pane) = self.get_pane_at(point, false).with_context(err_context)? {
let relative_position = pane.relative_position(point);
if let Some(mouse_event) = pane.mouse_scroll_up(&relative_position) {
- self.write_to_terminal_at(mouse_event.into_bytes(), point)
+ self.write_to_terminal_at(mouse_event.into_bytes(), point, client_id)
.with_context(err_context)?;
} else if pane.is_alternate_mode_active() {
// faux scrolling, send UP n times
// do n separate writes to make sure the sequence gets adjusted for cursor keys mode
for _ in 0..lines {
- self.write_to_terminal_at("\u{1b}[A".as_bytes().to_owned(), point)
+ self.write_to_terminal_at("\u{1b}[A".as_bytes().to_owned(), point, client_id)
.with_context(err_context)?;
}
} else {
@@ -2623,13 +2633,13 @@ impl Tab {
if let Some(pane) = self.get_pane_at(point, false).with_context(err_context)? {
let relative_position = pane.relative_position(point);
if let Some(mouse_event) = pane.mouse_scroll_down(&relative_position) {
- self.write_to_terminal_at(mouse_event.into_bytes(), point)
+ self.write_to_terminal_at(mouse_event.into_bytes(), point, client_id)
.with_context(err_context)?;
} else if pane.is_alternate_mode_active() {
// faux scrolling, send DOWN n times
// do n separate writes to make sure the sequence gets adjusted for cursor keys mode
for _ in 0..lines {
- self.write_to_terminal_at("\u{1b}[B".as_bytes().to_owned(), point)
+ self.write_to_terminal_at("\u{1b}[B".as_bytes().to_owned(), point, client_id)
.with_context(err_context)?;
}
} else {
diff --git a/zellij-server/src/tab/unit/tab_tests.rs b/zellij-server/src/tab/unit/tab_tests.rs
index cb3d8f787..bcf02202c 100644
--- a/zellij-server/src/tab/unit/tab_tests.rs
+++ b/zellij-server/src/tab/unit/tab_tests.rs
@@ -330,7 +330,7 @@ fn write_to_suppressed_pane() {
// Make sure it's suppressed now
tab.suppressed_panes.get(&PaneId::Terminal(2)).unwrap();
// Write content to it
- tab.write_to_pane_id(vec![34, 127, 31, 82, 17, 182], PaneId::Terminal(2))
+ tab.write_to_pane_id(vec![34, 127, 31, 82, 17, 182], PaneId::Terminal(2), None)
.unwrap();
}