@@ -826,42 +826,57 @@ fb_actions.path_separator = function(prompt_bufnr)
826826 local dir = Path :new (current_picker .finder .path .. os_sep .. current_picker :_get_prompt () .. os_sep )
827827
828828 if current_picker .finder .files and dir :exists () and dir :is_dir () then
829- fb_actions .open_dir (prompt_bufnr , dir .filename )
829+ fb_actions .open_dir (prompt_bufnr , nil , dir .filename )
830830 else
831831 vim .api .nvim_feedkeys (vim .api .nvim_replace_termcodes (os_sep , true , false , true ), " tn" , false )
832832 end
833833end
834834
835- fb_actions .open_dir = function (prompt_bufnr , dir )
836- local current_picker = action_state .get_current_picker (prompt_bufnr )
837- local finder = current_picker .finder
838- local entry = action_state .get_selected_entry ()
835+ --- get directory path to open based on `collapse_dirs` options
836+ --- @param finder any
837+ --- @param path string
838+ --- @param upward boolean whether to " cd" upwards
839+ --- @return string ? #path string
840+ local function open_dir_path (finder , path , upward )
841+ path = vim .loop .fs_realpath (path ) or " "
842+ if path == " " then
843+ return
844+ end
839845
840- if not vim .loop .fs_access (entry . path , " X" ) then
846+ if not vim .loop .fs_access (path , " X" ) then
841847 fb_utils .notify (" select" , { level = " WARN" , msg = " Permission denied" })
842848 return
843849 end
844850
845- local path = vim .loop .fs_realpath (dir :match (" ^" .. os_sep ) and dir or entry .path )
851+ if not finder .files or not finder .collapse_dirs then
852+ return path
853+ end
846854
847- if finder .files and finder .collapse_dirs then
848- local upwards = path == Path :new (finder .path ):parent ():absolute ()
849- while true do
850- local dirs = scan .scan_dir (path , { add_dirs = true , depth = 1 , hidden = true })
851- if # dirs == 1 and vim .fn .isdirectory (dirs [1 ]) then
852- path = upwards and Path :new (path ):parent ():absolute () or dirs [1 ]
853- -- make sure it's upper bound (#dirs == 1 implicitly reflects lower bound)
854- if path == Path :new (path ):parent ():absolute () then
855- break
856- end
857- else
858- break
859- end
855+ while true do
856+ local dirs = scan .scan_dir (path , { add_dirs = true , depth = 1 , hidden = true })
857+ if # dirs == 1 and vim .fn .isdirectory (dirs [1 ]) == 1 then
858+ path = upward and Path :new (path ):parent ():absolute () or dirs [1 ]
859+ else
860+ break
860861 end
861862 end
863+ return path
864+ end
865+
866+ --- comment open directory and refresh picker
867+ --- @param prompt_bufnr integer
868+ --- @param _ any select type
869+ --- @param dir string ? priority dir path
870+ fb_actions .open_dir = function (prompt_bufnr , _ , dir )
871+ local current_picker = action_state .get_current_picker (prompt_bufnr )
872+ local finder = current_picker .finder
873+ local entry = action_state .get_selected_entry ()
874+
875+ local path = dir or entry .path
876+ local upward = path == Path :new (finder .path ):parent ():absolute ()
862877
863878 finder .files = true
864- finder .path = path
879+ finder .path = open_dir_path ( finder , path , upward )
865880 fb_utils .redraw_border_title (current_picker )
866881 current_picker :refresh (
867882 finder ,
0 commit comments