@@ -11,6 +11,17 @@ local M = {
1111 init_root = " " ,
1212}
1313
14+ --- Helper function to execute some explorer method safely
15+ --- @param fn string # key of explorer
16+ --- @param ... any | nil
17+ --- @return function | nil
18+ local function explorer_fn (fn , ...)
19+ local explorer = core .get_explorer ()
20+ if explorer then
21+ return explorer [fn ](explorer , ... )
22+ end
23+ end
24+
1425--- Update the tree root to a directory or the directory containing
1526--- @param path string relative or absolute
1627--- @param bufnr number | nil
@@ -47,7 +58,7 @@ function M.change_root(path, bufnr)
4758 -- test if in vim_cwd
4859 if utils .path_relative (path , vim_cwd ) ~= path then
4960 if vim_cwd ~= cwd then
50- actions . root . change_dir . fn ( vim_cwd )
61+ explorer_fn ( " change_dir " , vim_cwd )
5162 end
5263 return
5364 end
@@ -58,19 +69,19 @@ function M.change_root(path, bufnr)
5869
5970 -- otherwise test M.init_root
6071 if _config .prefer_startup_root and utils .path_relative (path , M .init_root ) ~= path then
61- actions . root . change_dir . fn ( M .init_root )
72+ explorer_fn ( " change_dir " , M .init_root )
6273 return
6374 end
6475 -- otherwise root_dirs
6576 for _ , dir in pairs (_config .root_dirs ) do
6677 dir = vim .fn .fnamemodify (dir , " :p" )
6778 if utils .path_relative (path , dir ) ~= path then
68- actions . root . change_dir . fn ( dir )
79+ explorer_fn ( " change_dir " , dir )
6980 return
7081 end
7182 end
7283 -- finally fall back to the folder containing the file
73- actions . root . change_dir . fn ( vim .fn .fnamemodify (path , " :p:h" ))
84+ explorer_fn ( " change_dir " , vim .fn .fnamemodify (path , " :p:h" ))
7485end
7586
7687function M .tab_enter ()
@@ -110,7 +121,13 @@ function M.open_on_directory()
110121 return
111122 end
112123
113- actions .root .change_dir .force_dirchange (bufname , true )
124+
125+ local explorer = core .get_explorer ()
126+ if not explorer then
127+ core .init (bufname )
128+ end
129+
130+ explorer_fn (" force_dirchange" , bufname , true , false )
114131end
115132
116133--- @return table
134151--- @param name string | nil
135152function M .change_dir (name )
136153 if name then
137- actions . root . change_dir . fn ( name )
154+ explorer_fn ( " change_dir " , name )
138155 end
139156
140157 if _config .update_focused_file .update_root .enable then
0 commit comments