diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-02-27 15:48:47 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2023-02-27 15:48:47 +0100 |
commit | 219578c7b79e34e01981f6be98c03acb0c9ffff1 (patch) | |
tree | 3ae595ea0e29e0092b1206be63ad23d94e411edf | |
parent | df822043ab2c19bd34581c5e0f137eb26b643d38 (diff) |
fix(layouts): properly set cwd for edit panes
5 files changed, 28 insertions, 13 deletions
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs index b6c66c75b..d40a166c9 100644 --- a/zellij-server/src/pty.rs +++ b/zellij-server/src/pty.rs @@ -822,7 +822,7 @@ impl Pty { }, } }, - Some(Run::EditFile(path_to_file, line_number)) => { + Some(Run::EditFile(path_to_file, line_number, cwd)) => { let starts_held = false; // we do not hold edit panes (for now?) match self .bus @@ -831,7 +831,7 @@ impl Pty { .context("no OS I/O interface found") .with_context(err_context)? .spawn_terminal( - TerminalAction::OpenFile(path_to_file, line_number, None), + TerminalAction::OpenFile(path_to_file, line_number, cwd), quit_cb, self.default_editor.clone(), ) diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index a0d61b241..1ba9b735c 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -73,7 +73,7 @@ pub enum Run { Plugin(RunPlugin), #[serde(rename = "command")] Command(RunCommand), - EditFile(PathBuf, Option<usize>), // TODO: merge this with TerminalAction::OpenFile + EditFile(PathBuf, Option<usize>, Option<PathBuf>), // TODO: merge this with TerminalAction::OpenFile Cwd(PathBuf), } @@ -108,13 +108,14 @@ impl Run { }, ( Some(Run::Command(base_run_command)), - Some(Run::EditFile(file_to_edit, line_number)), + Some(Run::EditFile(file_to_edit, line_number, edit_cwd)), ) => match &base_run_command.cwd { - Some(cwd) => Some(Run::EditFile(cwd.join(&file_to_edit), *line_number)), - None => Some(Run::EditFile(file_to_edit.clone(), *line_number)), + Some(cwd) => Some(Run::EditFile(cwd.join(&file_to_edit), *line_number, Some(cwd.join(edit_cwd.clone().unwrap_or_default())))), + None => Some(Run::EditFile(file_to_edit.clone(), *line_number, edit_cwd.clone())), }, - (Some(Run::Cwd(cwd)), Some(Run::EditFile(file_to_edit, line_number))) => { - Some(Run::EditFile(cwd.join(&file_to_edit), *line_number)) + (Some(Run::Cwd(cwd)), Some(Run::EditFile(file_to_edit, line_number, edit_cwd))) => { + let cwd = edit_cwd.clone().unwrap_or(cwd.clone()); + Some(Run::EditFile(cwd.join(&file_to_edit), *line_number, Some(cwd))) }, (Some(_base), Some(other)) => Some(other.clone()), (Some(base), _) => Some(base.clone()), @@ -132,7 +133,15 @@ impl Run { run_command.cwd = Some(cwd.clone()); }, }, - Run::EditFile(path_to_file, _line_number) => { + Run::EditFile(path_to_file, _line_number, edit_cwd) => { + match edit_cwd.as_mut() { + Some(edit_cwd) => { + *edit_cwd = cwd.join(&edit_cwd); + }, + None => { + let _ = edit_cwd.insert(cwd.clone()); + } + }; *path_to_file = cwd.join(&path_to_file); }, Run::Cwd(path) => { diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap index 34d0fb321..68661a9c5 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_bare_propagated_to_its_consumer_edit.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1558 +assertion_line: 1614 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -21,6 +21,9 @@ Layout { EditFile( "/tmp/foo/bar", None, + Some( + "/tmp/foo", + ), ), ), borderless: false, diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap index 298be4e00..47469139b 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__pane_template_with_command_propagated_to_its_consumer_edit.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 1574 +assertion_line: 1630 expression: "format!(\"{:#?}\", layout)" --- Layout { @@ -21,6 +21,9 @@ Layout { EditFile( "/tmp/foo/bar", None, + Some( + "/tmp/foo/", + ), ), ), borderless: false, diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs index 11c139f4c..402dede99 100644 --- a/zellij-utils/src/kdl/kdl_layout_parser.rs +++ b/zellij-utils/src/kdl/kdl_layout_parser.rs @@ -374,8 +374,8 @@ impl<'a> KdlLayoutParser<'a> { hold_on_close, hold_on_start, }))), - (None, Some(edit), Some(cwd)) => Ok(Some(Run::EditFile(cwd.join(edit), None))), - (None, Some(edit), None) => Ok(Some(Run::EditFile(edit, None))), + (None, Some(edit), Some(cwd)) => Ok(Some(Run::EditFile(cwd.join(edit), None, Some(cwd)))), + (None, Some(edit), None) => Ok(Some(Run::EditFile(edit, None, None))), (Some(_command), Some(_edit), _) => Err(ConfigError::new_layout_kdl_error( "cannot have both a command and an edit instruction for the same pane".into(), pane_node.span().offset(), |