diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-04-05 18:43:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-05 18:43:14 +0200 |
commit | 462239b535c22eac29634e210ad86dde3fda37ce (patch) | |
tree | d94aa5cc0c725487e6ffeb50f50963cfe9c6ba0e | |
parent | 52e81bec7d88e8d27736698ce211473191585575 (diff) |
fix(plugins): various pre-release issues (#3246)
* fix(strider): close_self instead of close_focus
* fix(plugins): populate caller_cwd for all aliases
* fix(config): launch the session-manager alias rather than the explicit internal url
* style(fmt): rustfmt
* fix tests
10 files changed, 68 insertions, 51 deletions
diff --git a/default-plugins/strider/src/state.rs b/default-plugins/strider/src/state.rs index 1ff583862..4b81c7f20 100644 --- a/default-plugins/strider/src/state.rs +++ b/default-plugins/strider/src/state.rs @@ -158,7 +158,7 @@ impl State { } } if self.close_on_selection { - close_focus(); + close_self(); } } pub fn send_filepick_response(&mut self) { @@ -178,7 +178,7 @@ impl State { .with_payload(selected_path.display().to_string()), ); #[cfg(target_family = "wasm")] - close_focus(); + close_self(); }, Some((PipeSource::Cli(pipe_id), _args)) => { #[cfg(target_family = "wasm")] @@ -186,7 +186,7 @@ impl State { #[cfg(target_family = "wasm")] unblock_cli_pipe_input(pipe_id); #[cfg(target_family = "wasm")] - close_focus(); + close_self(); }, _ => {}, } diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index c4e810536..5877e56df 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -1348,7 +1348,7 @@ impl Pty { should_float: Option<bool>, should_open_in_place: bool, // should be opened in place pane_title: Option<String>, // pane title - run: RunPluginOrAlias, + mut run: RunPluginOrAlias, tab_index: usize, // tab index pane_id_to_replace: Option<PaneId>, // pane id to replace if this is to be opened "in-place" client_id: ClientId, @@ -1359,7 +1359,7 @@ impl Pty { // of the pipeline between threads and end up needing to forward this _floating_pane_coordinates: Option<FloatingPaneCoordinates>, ) -> Result<()> { - let cwd = cwd.or_else(|| { + let get_focused_cwd = || { self.active_panes .get(&client_id) .and_then(|pane| match pane { @@ -1372,8 +1372,14 @@ impl Pty { .as_ref() .and_then(|input| input.get_cwd(Pid::from_raw(id))) }) - }); + }; + let cwd = cwd.or_else(get_focused_cwd); + + if let RunPluginOrAlias::Alias(alias) = &mut run { + let cwd = get_focused_cwd(); + alias.set_caller_cwd_if_not_set(cwd); + } self.bus.senders.send_to_plugin(PluginInstruction::Load( should_float, should_open_in_place, diff --git a/zellij-server/src/screen.rs b/zellij-server/src/screen.rs index 5384987de..f5458c1a8 100644 --- a/zellij-server/src/screen.rs +++ b/zellij-server/src/screen.rs @@ -3544,7 +3544,7 @@ pub(crate) fn screen_thread_main( should_float, Some(run_plugin), None, - None, + Some(client_id), ) }, ?); } else if let Some(active_tab) = diff --git a/zellij-utils/assets/config/default.kdl b/zellij-utils/assets/config/default.kdl index f3decbc9e..c8b8f6a19 100644 --- a/zellij-utils/assets/config/default.kdl +++ b/zellij-utils/assets/config/default.kdl @@ -114,7 +114,7 @@ keybinds { bind "Ctrl s" { SwitchToMode "Scroll"; } bind "d" { Detach; } bind "w" { - LaunchOrFocusPlugin "zellij:session-manager" { + LaunchOrFocusPlugin "session-manager" { floating true move_to_focused_tab true }; diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index 61a789d1f..52c18fb50 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -380,15 +380,13 @@ impl Action { }) }, Err(_) => { - let mut user_configuration = - configuration.map(|c| c.inner().clone()).unwrap_or_default(); - user_configuration - .insert("caller_cwd".to_owned(), current_dir.display().to_string()); - RunPluginOrAlias::Alias(PluginAlias::new( + let mut plugin_alias = PluginAlias::new( &plugin, - &Some(user_configuration), + &configuration.map(|c| c.inner().clone()), alias_cwd, - )) + ); + plugin_alias.set_caller_cwd_if_not_set(Some(current_dir)); + RunPluginOrAlias::Alias(plugin_alias) }, }; if floating { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index cede261e7..1235f3d2b 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -456,6 +456,27 @@ impl PluginAlias { ..Default::default() } } + pub fn set_caller_cwd_if_not_set(&mut self, caller_cwd: Option<PathBuf>) { + // we do this only for an alias because in all other cases this will be handled by the + // "cwd" configuration key above + // for an alias we might have cases where the cwd is defined on the alias but we still + // want to pass the "caller" cwd for the plugin the alias resolves into (eg. a + // filepicker that has access to the whole filesystem but wants to start in a specific + // folder) + if let Some(caller_cwd) = caller_cwd { + if self + .configuration + .as_ref() + .map(|c| c.inner().get("caller_cwd").is_none()) + .unwrap_or(true) + { + let configuration = self + .configuration + .get_or_insert_with(|| PluginUserConfiguration::new(BTreeMap::new())); + configuration.insert("caller_cwd", caller_cwd.display().to_string()); + } + } + } } #[allow(clippy::derive_hash_xor_eq)] diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap index 9ab05955c..5bf50ad44 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap @@ -2655,18 +2655,16 @@ Config { 'w', ): [ LaunchOrFocusPlugin( - RunPlugin( - RunPlugin { - _allow_exec_host_cmd: false, - location: Zellij( - PluginTag( - "session-manager", + Alias( + PluginAlias { + name: "session-manager", + configuration: Some( + PluginUserConfiguration( + {}, ), ), - configuration: PluginUserConfiguration( - {}, - ), initial_cwd: None, + run_plugin: None, }, ), true, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap index 24d28bf6e..00ddc30ab 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap @@ -2655,18 +2655,16 @@ Config { 'w', ): [ LaunchOrFocusPlugin( - RunPlugin( - RunPlugin { - _allow_exec_host_cmd: false, - location: Zellij( - PluginTag( - "session-manager", + Alias( + PluginAlias { + name: "session-manager", + configuration: Some( + PluginUserConfiguration( + {}, ), ), - configuration: PluginUserConfiguration( - {}, - ), initial_cwd: None, + run_plugin: None, }, ), true, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap index 9721747b1..1580d46c7 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap @@ -2655,18 +2655,16 @@ Config { 'w', ): [ LaunchOrFocusPlugin( - RunPlugin( - RunPlugin { - _allow_exec_host_cmd: false, - location: Zellij( - PluginTag( - "session-manager", + Alias( + PluginAlias { + name: "session-manager", + configuration: Some( + PluginUserConfiguration( + {}, ), ), - configuration: PluginUserConfiguration( - {}, - ), initial_cwd: None, + run_plugin: None, }, ), true, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap index a458ff10d..6e5b86860 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap @@ -2655,18 +2655,16 @@ Config { 'w', ): [ LaunchOrFocusPlugin( - RunPlugin( - RunPlugin { - _allow_exec_host_cmd: false, - location: Zellij( - PluginTag( - "session-manager", + Alias( + PluginAlias { + name: "session-manager", + configuration: Some( + PluginUserConfiguration( + {}, ), ), - configuration: PluginUserConfiguration( - {}, - ), initial_cwd: None, + run_plugin: None, }, ), true, |