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
This commit is contained in:
Aram Drevekenin 2024-04-05 18:43:14 +02:00 committed by GitHub
parent 52e81bec7d
commit 462239b535
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 68 additions and 51 deletions

View File

@ -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();
},
_ => {},
}

View File

@ -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,

View File

@ -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) =

View File

@ -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
};

View File

@ -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 {

View File

@ -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)]

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,