Skip to content

Commit 2b2f748

Browse files
authored
feat: add "none" as an option for cwd_target (#837)
1 parent 30bf4ef commit 2b2f748

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

doc/neo-tree.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ These defaults can be changed by setting the following options:
787787
<
788788

789789
In addition to `"tab"` and `"window"`, you can also set the target to `"global"`
790-
for either option, which is the same as using the |cd| command.
790+
for either option, which is the same as using the |cd| command. Setting the target
791+
to `"none"` will prevent neo-tree from setting vim's cwd for that position.
791792

792793

793794
FILTERED ITEMS *neo-tree-filtered-items*

lua/neo-tree/sources/manager.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ local get_params_for_cwd = function(state)
302302
return winid, tabnr
303303
elseif target == "global" then
304304
return -1, -1
305+
elseif target == "none" then
306+
return nil, nil
305307
else -- default to tab
306308
return -1, tabnr
307309
end
@@ -312,7 +314,10 @@ end
312314

313315
M.get_cwd = function(state)
314316
local winid, tabnr = get_params_for_cwd(state)
315-
local success, cwd = pcall(vim.fn.getcwd, winid, tabnr)
317+
local success, cwd = false, ""
318+
if winid or tabnr then
319+
success, cwd = pcall(vim.fn.getcwd, winid, tabnr)
320+
end
316321
if success then
317322
return cwd
318323
else
@@ -331,6 +336,11 @@ M.set_cwd = function(state)
331336
end
332337

333338
local winid, tabnr = get_params_for_cwd(state)
339+
340+
if winid == nil and tabnr == nil then
341+
return
342+
end
343+
334344
local _, cwd = pcall(vim.fn.getcwd, winid, tabnr)
335345
if state.path ~= cwd then
336346
if winid > 0 then

0 commit comments

Comments
 (0)