aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-04-16 20:57:01 +0800
committerGitHub <noreply@github.com>2024-04-16 20:57:01 +0800
commit5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98 (patch)
tree8d058733804bed0990c1a8e6836663f7b2460d5d /src/nvim/window.c
parent2fc2343728831d890a043def5d9d714947737cf6 (diff)
downloadrneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.tar.gz
rneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.tar.bz2
rneovim-5cfdaaaeac0f53a621696d8eb6b5a3ba90438c98.zip
fix(api): ignore 'autochdir' when renaming other buf (#28376)
Problem: Renaming non-current buffer changes working directory when 'autochdir' is set. Solution: Temporarily disable 'autochdir'. Add more tests for the win_set_buf change.
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 85ed73bd6d..ea879d450b 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -752,15 +752,20 @@ void win_set_buf(win_T *win, buf_T *buf, Error *err)
goto cleanup;
}
- // temporarily disable 'autochdir' when using win_set_buf
- // on non-current window
- int save_acd = p_acd;
+ try_start();
+
+ const int save_acd = p_acd;
if (!switchwin.sw_same_win) {
+ // Temporarily disable 'autochdir' when setting buffer in another window.
p_acd = false;
}
- try_start();
+
int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
- p_acd = save_acd;
+
+ if (!switchwin.sw_same_win) {
+ p_acd = save_acd;
+ }
+
if (!try_end(err) && result == FAIL) {
api_set_error(err,
kErrorTypeException,