File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -2663,10 +2663,15 @@ H.picker_choose = function(picker, pre_command)
26632663
26642664 local win_id_target = picker .windows .target
26652665 if pre_command ~= nil and H .is_valid_win (win_id_target ) then
2666+ -- Work around Neovim not preserving cwd during `nvim_win_call`
2667+ -- See: https://github.com/neovim/neovim/issues/32203
2668+ local picker_cwd , global_cwd = vim .fn .getcwd (0 ), vim .fn .getcwd (- 1 , - 1 )
2669+ vim .fn .chdir (global_cwd )
26662670 vim .api .nvim_win_call (win_id_target , function ()
26672671 vim .cmd (pre_command )
26682672 picker .windows .target = vim .api .nvim_get_current_win ()
26692673 end )
2674+ vim .fn .chdir (picker_cwd )
26702675 end
26712676
26722677 local ok , res = pcall (picker .opts .source .choose , cur_item )
@@ -3509,7 +3514,7 @@ H.win_set_cwd = function(win_id, cwd)
35093514 if cwd == nil or vim .fn .getcwd (win_id or 0 ) == cwd then return end
35103515 local f = function () vim .cmd (' lcd ' .. vim .fn .fnameescape (cwd )) end
35113516 if win_id == nil or win_id == vim .api .nvim_get_current_win () then return f () end
3512- vim .api .nvim_win_call (f , win_id )
3517+ vim .api .nvim_win_call (win_id , f )
35133518end
35143519
35153520H .seq_along = function (arr )
Original file line number Diff line number Diff line change @@ -5444,10 +5444,14 @@ T['Choose'] = new_set()
54445444
54455445T [' Choose' ][' works for split/tab variations' ] = function ()
54465446 local validate = function (key )
5447+ local global_cwd = child .fn .getcwd (- 1 , - 1 )
5448+ child .lua (' _G.source_cwd = ' .. vim .inspect (test_dir_absolute ))
5449+
54475450 local win_id_init = child .api .nvim_get_current_win ()
54485451 child .lua_notify ([[ MiniPick.start({
54495452 source = {
54505453 items = { 'a' },
5454+ cwd = _G.source_cwd,
54515455 choose = function() _G.target_window = MiniPick.get_picker_state().windows.target end,
54525456 },
54535457 })]] )
@@ -5458,6 +5462,10 @@ T['Choose']['works for split/tab variations'] = function()
54585462 -- Should modify target window
54595463 eq (child .lua_get (' _G.target_window' ) ~= win_id_init , true )
54605464
5465+ -- Should not modify any current directory
5466+ eq (child .fn .getcwd (- 1 , - 1 ), global_cwd )
5467+ eq (child .fn .getcwd (0 ), global_cwd )
5468+
54615469 -- Cleanup
54625470 child .lua (' _G.target_window = nil' )
54635471 end
You can’t perform that action at this time.
0 commit comments