aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-12 13:16:00 +0200
committeruser <user@clank>2026-08-12 13:16:00 +0200
commit733ac78ca77cc61b52bb627e4c02eafa80282944 (patch)
treef553706a88fa05f8f1ade8efb39b5475ded160d3 /zellij-server/src
parentsl0p(pane-finder): document a single-chord binding (diff)
downloadsl0ppij-733ac78ca77cc61b52bb627e4c02eafa80282944.tar.gz
sl0ppij-733ac78ca77cc61b52bb627e4c02eafa80282944.tar.xz
sl0ppij-733ac78ca77cc61b52bb627e4c02eafa80282944.zip
sl0p: add close_if_focused to LaunchOrFocusPlugin
Upstream's action focuses an already-running plugin, so a chord bound to it can only ever open one -- there is no way to dismiss with the same key. This cannot be fixed in a plugin. Keybindings are resolved into actions in route.rs before a key reaches a pane, so the launching chord never arrives at the plugin. intercept_key_presses does not help either: the intercept lives in screen.rs and only sees keys that already became Action::Write, i.e. keys destined for a pane. Confirmed empirically -- an intercepting build received Ctrl-u but never Ctrl-;. Closes only when the plugin is the focused pane in the client's ACTIVE tab, so the chord cannot close whatever pane the user happens to be on. A plugin that exists but is hidden behind a floating-layer toggle, or is focused in a different tab, is revealed or brought over as before. Defaults to false, so every existing binding is unaffected. Config-only, with no protobuf representation: defaulted at both boundaries and dropped when an action crosses the plugin API, so no prost regeneration is needed. The 24 snapshot lines are the new field appearing in serialised keybind dumps.
Diffstat (limited to 'zellij-server/src')
-rw-r--r--zellij-server/src/route.rs2
-rw-r--r--zellij-server/src/screen.rs43
2 files changed, 44 insertions, 1 deletions
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index 85312048..8783af72 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -1428,6 +1428,7 @@ pub(crate) fn route_action(
close_replaced_pane,
skip_cache,
tab_id,
+ close_if_focused,
} => {
senders
.send_to_screen(ScreenInstruction::LaunchOrFocusPlugin(
@@ -1441,6 +1442,7 @@ pub(crate) fn route_action(
client_id,
Some(NotificationEnd::new(completion_tx)),
tab_id,
+ close_if_focused,
))
.with_context(err_context)?;
},
diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs
index 0ec911f6..a5d0fd30 100644
--- a/zellij-server/src/screen.rs
+++ b/zellij-server/src/screen.rs
@@ -699,6 +699,7 @@ pub enum ScreenInstruction {
ClientId,
Option<NotificationEnd>,
Option<usize>, // tab_id
+ bool, // close_if_focused
), // bools are: should_float, move_to_focused_tab, should_open_in_place, close_replaced_pane, Option<PaneId> is the pane id to replace, bool following it is skip_cache
LaunchPlugin(
RunPluginOrAlias,
@@ -5747,6 +5748,28 @@ impl Screen {
self.render(None)
}
+ /// Whether a plugin matching `run_plugin` is the client's currently focused
+ /// pane.
+ ///
+ /// Only the client's own active tab is considered: a plugin focused in some
+ /// other tab is not what the user is looking at, so the chord should bring it
+ /// here rather than close it.
+ pub fn plugin_pane_is_focused(
+ &self,
+ run_plugin: &RunPluginOrAlias,
+ client_id: ClientId,
+ ) -> bool {
+ let Ok(active_tab) = self.get_active_tab(client_id) else {
+ return false;
+ };
+ match (
+ active_tab.find_plugin(run_plugin),
+ active_tab.get_active_pane_id(client_id),
+ ) {
+ (Some(plugin_pane_id), Some(focused_pane_id)) => plugin_pane_id == focused_pane_id,
+ _ => false,
+ }
+ }
pub fn focus_plugin_pane(
&mut self,
run_plugin: &RunPluginOrAlias,
@@ -10323,6 +10346,7 @@ pub(crate) fn screen_thread_main(
client_id,
mut completion_tx,
explicit_tab_id,
+ close_if_focused,
) => match pane_id_to_replace {
Some(pane_id_to_replace) if should_open_in_place => {
let resolved_tab_index =
@@ -10374,7 +10398,24 @@ pub(crate) fn screen_thread_main(
.or(client_id_and_focused_tab);
match resolved_tab_and_client {
Some((tab_index, client_id)) => {
- if screen.focus_plugin_pane(
+ // Dismiss on the same chord that opened it, so one
+ // key toggles. Has to happen here rather than in the
+ // plugin: keybindings are resolved into actions
+ // before a key can reach a pane, so the launching
+ // chord never arrives at the plugin at all.
+ if close_if_focused
+ && screen.plugin_pane_is_focused(&run_plugin, client_id)
+ {
+ active_tab_and_connected_client_id!(
+ screen,
+ client_id,
+ |tab: &mut Tab, client_id: ClientId| tab
+ .close_focused_pane(client_id, completion_tx),
+ ?
+ );
+ screen.render(None)?;
+ screen.log_and_report_session_state()?;
+ } else if screen.focus_plugin_pane(
&run_plugin,
should_float,
move_to_focused_tab,