diff --git a/CHANGELOG.md b/CHANGELOG.md index f45af785..829ed649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * fix: account for emoji/widechars when double/triple-clicking to mark words (https://github.com/zellij-org/zellij/pull/4302) * fix: allow pasting and emojis in tab/pane names and pasting in search (https://github.com/zellij-org/zellij/pull/4303) * fix: stack pane ordering when stacking multiple panes (https://github.com/zellij-org/zellij/pull/4308) +* fix: normalize focusing of plugins launched through pipes (https://github.com/zellij-org/zellij/pull/4309) ## [0.42.2] - 2025-04-15 * refactor(terminal): track scroll_region as tuple rather than Option (https://github.com/zellij-org/zellij/pull/4082) diff --git a/default-plugins/plugin-manager/src/main.rs b/default-plugins/plugin-manager/src/main.rs index c148a7ba..8e1c91a8 100644 --- a/default-plugins/plugin-manager/src/main.rs +++ b/default-plugins/plugin-manager/src/main.rs @@ -468,6 +468,7 @@ impl NewPluginScreen { .new_plugin_instance_should_have_pane_title( "Select a .wasm file to load as a plugin...", ) + .new_plugin_instance_should_be_focused() .with_args(args), ); }, diff --git a/default-plugins/session-manager/src/main.rs b/default-plugins/session-manager/src/main.rs index 8e1d039f..6be29dc5 100644 --- a/default-plugins/session-manager/src/main.rs +++ b/default-plugins/session-manager/src/main.rs @@ -249,6 +249,7 @@ impl State { .new_plugin_instance_should_have_pane_title( "Select folder for the new session...", ) + .new_plugin_instance_should_be_focused() .with_args(args), ); should_render = true; diff --git a/zellij-server/src/plugins/mod.rs b/zellij-server/src/plugins/mod.rs index 6e84649a..1c77df5e 100644 --- a/zellij-server/src/plugins/mod.rs +++ b/zellij-server/src/plugins/mod.rs @@ -715,6 +715,7 @@ pub(crate) fn plugin_thread_main( &mut wasm_bridge, &plugin_aliases, floating_pane_coordinates, + None, ); }, None => { @@ -777,6 +778,7 @@ pub(crate) fn plugin_thread_main( &mut wasm_bridge, &plugin_aliases, floating_pane_coordinates, + None, ); }, None => { @@ -842,6 +844,7 @@ pub(crate) fn plugin_thread_main( &mut wasm_bridge, &plugin_aliases, floating_pane_coordinates, + message.new_plugin_args.and_then(|n| n.should_focus), ); }, (None, Some(destination_plugin_id)) => { @@ -1047,6 +1050,7 @@ fn pipe_to_specific_plugins( wasm_bridge: &mut WasmBridge, plugin_aliases: &PluginAliases, floating_pane_coordinates: Option, + should_focus: Option, ) { let is_private = true; let size = Size::default(); @@ -1069,6 +1073,7 @@ fn pipe_to_specific_plugins( pane_id_to_replace.clone(), cli_client_id, floating_pane_coordinates, + should_focus.unwrap_or(false), ); for (plugin_id, client_id) in all_plugin_ids { pipe_messages.push(( diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs index 9ccd7c1d..fbb67a5e 100644 --- a/zellij-server/src/plugins/wasm_bridge.rs +++ b/zellij-server/src/plugins/wasm_bridge.rs @@ -1427,6 +1427,7 @@ impl WasmBridge { pane_id_to_replace: Option, cli_client_id: Option, floating_pane_coordinates: Option, + should_focus: bool, ) -> Vec<(PluginId, Option)> { let run_plugin = run_plugin_or_alias.get_run_plugin(); match run_plugin { @@ -1453,8 +1454,6 @@ impl WasmBridge { ) { Ok((plugin_id, client_id)) => { let start_suppressed = false; - let should_focus = Some(false); // we should not focus plugins that - // were started from another plugin drop(self.senders.send_to_screen(ScreenInstruction::AddPlugin( Some(should_float), should_be_open_in_place, @@ -1466,7 +1465,7 @@ impl WasmBridge { cwd, start_suppressed, floating_pane_coordinates, - should_focus, + Some(should_focus), Some(client_id), ))); vec![(plugin_id, Some(client_id))] diff --git a/zellij-utils/assets/prost/api.plugin_command.rs b/zellij-utils/assets/prost/api.plugin_command.rs index 0c290fc3..6e80de23 100644 --- a/zellij-utils/assets/prost/api.plugin_command.rs +++ b/zellij-utils/assets/prost/api.plugin_command.rs @@ -660,6 +660,8 @@ pub struct NewPluginArgs { pub cwd: ::core::option::Option<::prost::alloc::string::String>, #[prost(bool, tag="5")] pub skip_cache: bool, + #[prost(bool, optional, tag="6")] + pub should_focus: ::core::option::Option, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 91f2c713..42635864 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -1988,6 +1988,7 @@ pub struct NewPluginArgs { pub pane_title: Option, pub cwd: Option, pub skip_cache: bool, + pub should_focus: Option, } #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -2077,6 +2078,11 @@ impl MessageToPlugin { new_plugin_args.skip_cache = true; self } + pub fn new_plugin_instance_should_be_focused(mut self) -> Self { + let new_plugin_args = self.new_plugin_args.get_or_insert_with(Default::default); + new_plugin_args.should_focus = Some(true); + self + } } #[derive(Debug, Default, Clone, Serialize, Deserialize)] diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto index d46ba1e3..106544e0 100644 --- a/zellij-utils/src/plugin_api/plugin_command.proto +++ b/zellij-utils/src/plugin_api/plugin_command.proto @@ -545,6 +545,7 @@ message NewPluginArgs { optional string pane_title = 3; optional string cwd = 4; bool skip_cache = 5; + optional bool should_focus = 6; } message PaneId { diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs index 073284bc..f5411cb8 100644 --- a/zellij-utils/src/plugin_api/plugin_command.rs +++ b/zellij-utils/src/plugin_api/plugin_command.rs @@ -971,6 +971,7 @@ impl TryFrom for PluginCommand { pane_title: protobuf_new_plugin_args.pane_title, cwd: protobuf_new_plugin_args.cwd.map(|cwd| PathBuf::from(cwd)), skip_cache: protobuf_new_plugin_args.skip_cache, + should_focus: protobuf_new_plugin_args.should_focus, }) }), destination_plugin_id, @@ -2260,6 +2261,7 @@ impl TryFrom for ProtobufPluginCommand { pane_title: m_t_p.pane_title, cwd: m_t_p.cwd.map(|cwd| cwd.display().to_string()), skip_cache: m_t_p.skip_cache, + should_focus: m_t_p.should_focus, } }), destination_plugin_id: message_to_plugin.destination_plugin_id,