summaryrefslogtreecommitdiffstats
path: root/zellij-server
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2023-02-27 16:34:31 +0100
committerGitHub <noreply@github.com>2023-02-27 16:34:31 +0100
commit149cafc6d66086c5f42c3f2f82c442d438e5b2c4 (patch)
tree89c11faf8a90d82b68d0b47b82398c543ddcfa4e /zellij-server
parentd20720f443c9b934f4db13701fd6f30202a773de (diff)
fix(cli): edit cwd (#2201)
* fix(cli): properly set cwd for edit panes * fix(layouts): properly set cwd for edit panes * style(fmt): rustfmt
Diffstat (limited to 'zellij-server')
-rw-r--r--zellij-server/src/os_input_output.rs9
-rw-r--r--zellij-server/src/plugins/wasm_bridge.rs2
-rw-r--r--zellij-server/src/pty.rs6
-rw-r--r--zellij-server/src/route.rs4
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap4
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap4
-rw-r--r--zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap4
7 files changed, 19 insertions, 14 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs
index 6e11f5ed6..a3e1fa10e 100644
--- a/zellij-server/src/os_input_output.rs
+++ b/zellij-server/src/os_input_output.rs
@@ -277,7 +277,12 @@ fn spawn_terminal(
// secondary fd
let mut failover_cmd_args = None;
let cmd = match terminal_action {
- TerminalAction::OpenFile(file_to_open, line_number) => {
+ TerminalAction::OpenFile(mut file_to_open, line_number, cwd) => {
+ if file_to_open.is_relative() {
+ if let Some(cwd) = cwd.as_ref() {
+ file_to_open = cwd.join(file_to_open);
+ }
+ }
let mut command = default_editor.unwrap_or_else(|| {
PathBuf::from(
env::var("EDITOR")
@@ -318,7 +323,7 @@ fn spawn_terminal(
RunCommand {
command,
args,
- cwd: None,
+ cwd,
hold_on_close: false,
hold_on_start: false,
}
diff --git a/zellij-server/src/plugins/wasm_bridge.rs b/zellij-server/src/plugins/wasm_bridge.rs
index 77d979ac1..62e8cedb9 100644
--- a/zellij-server/src/plugins/wasm_bridge.rs
+++ b/zellij-server/src/plugins/wasm_bridge.rs
@@ -691,7 +691,7 @@ fn host_open_file(plugin_env: &PluginEnv) {
plugin_env
.senders
.send_to_pty(PtyInstruction::SpawnTerminal(
- Some(TerminalAction::OpenFile(path, None)),
+ Some(TerminalAction::OpenFile(path, None, None)),
None,
None,
ClientOrTabIndex::TabIndex(plugin_env.tab_index),
diff --git a/zellij-server/src/pty.rs b/zellij-server/src/pty.rs
index 4c4f0a910..d40a166c9 100644
--- a/zellij-server/src/pty.rs
+++ b/zellij-server/src/pty.rs
@@ -166,7 +166,7 @@ pub(crate) fn pty_thread_main(mut pty: Pty, layout: Box<Layout>) -> Result<()> {
|| format!("failed to open in-place editor for client {}", client_id);
match pty.spawn_terminal(
- Some(TerminalAction::OpenFile(temp_file, line_number)),
+ Some(TerminalAction::OpenFile(temp_file, line_number, None)),
ClientOrTabIndex::ClientId(client_id),
) {
Ok((pid, _starts_held)) => {
@@ -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),
+ TerminalAction::OpenFile(path_to_file, line_number, cwd),
quit_cb,
self.default_editor.clone(),
)
diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs
index 36799b5ad..53ccf964d 100644
--- a/zellij-server/src/route.rs
+++ b/zellij-server/src/route.rs
@@ -284,9 +284,9 @@ pub(crate) fn route_action(
.send_to_pty(pty_instr)
.with_context(err_context)?;
},
- Action::EditFile(path_to_file, line_number, split_direction, should_float) => {
+ Action::EditFile(path_to_file, line_number, cwd, split_direction, should_float) => {
let title = format!("Editing: {}", path_to_file.display());
- let open_file = TerminalAction::OpenFile(path_to_file, line_number);
+ let open_file = TerminalAction::OpenFile(path_to_file, line_number, cwd);
let pty_instr = match (split_direction, should_float) {
(Some(Direction::Left), false) => {
PtyInstruction::SpawnTerminalVertically(Some(open_file), Some(title), client_id)
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap
index 649328fe4..ccd71c6a3 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_default_parameters.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
-assertion_line: 1944
+assertion_line: 2102
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
-[SpawnTerminal(Some(OpenFile("/file/to/edit", None)), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
+[SpawnTerminal(Some(OpenFile("/file/to/edit", None, Some("."))), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap
index 92e668f41..485a2312a 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_line_number.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
-assertion_line: 1989
+assertion_line: 2140
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
-[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100))), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
+[SpawnTerminal(Some(OpenFile("/file/to/edit", Some(100), Some("."))), Some(false), Some("Editing: /file/to/edit"), ClientId(10)), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
diff --git a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap
index 3280a24e4..7b3459d5f 100644
--- a/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap
+++ b/zellij-server/src/unit/snapshots/zellij_server__screen__screen_tests__send_cli_edit_action_with_split_direction.snap
@@ -1,6 +1,6 @@
---
source: zellij-server/src/./unit/screen_tests.rs
-assertion_line: 2018
+assertion_line: 2178
expression: "format!(\"{:?}\", * received_pty_instructions.lock().unwrap())"
---
-[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None)), Some("Editing: /file/to/edit"), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]
+[SpawnTerminalHorizontally(Some(OpenFile("/file/to/edit", None, Some("."))), Some("Editing: /file/to/edit"), 10), UpdateActivePane(Some(Terminal(0)), 1), UpdateActivePane(Some(Terminal(0)), 1), Exit]