Skip to content

Commit

Permalink
fix(plugins): various plugin api and other fixes (zellij-org#3665)
Browse files Browse the repository at this point in the history
* fix(plugins): do not allow focusing an unselectable pane

* fix(folders): make sure config and cache folders exist on app start
  • Loading branch information
imsnif authored and Tomcat-42 committed Nov 9, 2024
1 parent 9740ba7 commit a342ad9
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod tests;
use zellij_utils::{
clap::Parser,
cli::{CliAction, CliArgs, Command, Sessions},
consts::create_config_and_cache_folders,
envs,
input::config::Config,
logging::*,
Expand All @@ -14,6 +15,7 @@ use zellij_utils::{

fn main() {
configure_logger();
create_config_and_cache_folders();
let opts = CliArgs::parse();

{
Expand Down
9 changes: 9 additions & 0 deletions zellij-server/src/panes/floating_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,15 @@ impl FloatingPanes {
self.set_force_render();
}
pub fn focus_pane(&mut self, pane_id: PaneId, client_id: ClientId) {
let pane_is_selectable = self
.panes
.get(&pane_id)
.map(|p| p.selectable())
.unwrap_or(false);
if !pane_is_selectable {
log::error!("Cannot focus pane {:?} as it is not selectable!", pane_id);
return;
}
self.active_panes
.insert(client_id, pane_id, &mut self.panes);
self.focus_pane_for_all_clients(pane_id);
Expand Down
9 changes: 9 additions & 0 deletions zellij-server/src/panes/tiled_panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ impl TiledPanes {
}
}
pub fn focus_pane(&mut self, pane_id: PaneId, client_id: ClientId) {
let pane_is_selectable = self
.panes
.get(&pane_id)
.map(|p| p.selectable())
.unwrap_or(false);
if !pane_is_selectable {
log::error!("Cannot focus pane {:?} as it is not selectable!", pane_id);
return;
}
if self.panes_to_hide.contains(&pane_id) {
// this means there is a fullscreen pane that is not the current pane, let's unset it
// before changing focus
Expand Down
3 changes: 2 additions & 1 deletion zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,8 @@ impl Tab {
focused_floating_pane
})
.or_else(|_| match self.suppressed_panes.remove(&pane_id) {
Some(pane) => {
Some(mut pane) => {
pane.1.set_selectable(true);
if should_float {
self.show_floating_panes();
self.add_floating_pane(pane.1, pane_id, None, Some(client_id))
Expand Down
17 changes: 17 additions & 0 deletions zellij-utils/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Zellij program-wide constants.
use crate::home::find_default_config_dir;
use directories::ProjectDirs;
use include_dir::{include_dir, Dir};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -32,6 +33,22 @@ pub fn session_info_folder_for_session(session_name: &str) -> PathBuf {
ZELLIJ_SESSION_INFO_CACHE_DIR.join(session_name)
}

pub fn create_config_and_cache_folders() {
if let Err(e) = std::fs::create_dir_all(&ZELLIJ_CACHE_DIR.as_path()) {
log::error!("Failed to create cache dir: {:?}", e);
}
if let Some(config_dir) = find_default_config_dir() {
if let Err(e) = std::fs::create_dir_all(&config_dir.as_path()) {
log::error!("Failed to create config dir: {:?}", e);
}
}
// while session_info is a child of cache currently, it won't necessarily always be this way,
// and so it's explicitly created here
if let Err(e) = std::fs::create_dir_all(&ZELLIJ_SESSION_INFO_CACHE_DIR.as_path()) {
log::error!("Failed to create session_info cache dir: {:?}", e);
}
}

const fn system_default_data_dir() -> &'static str {
if let Some(data_dir) = std::option_env!("PREFIX") {
data_dir
Expand Down
10 changes: 0 additions & 10 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,6 @@ impl Action {
&run_plugin_or_alias.location_string() == plugin_url
},
Action::LaunchOrFocusPlugin(run_plugin_or_alias, ..) => {
log::info!(
"2: {:?} == {:?}",
run_plugin_or_alias.location_string(),
plugin_url
);
eprintln!(
"2: {:?} == {:?}",
run_plugin_or_alias.location_string(),
plugin_url
);
&run_plugin_or_alias.location_string() == plugin_url
},
_ => false,
Expand Down

0 comments on commit a342ad9

Please sign in to comment.