22local lib = require (" nvim-tree.lib" )
33local notify = require (" nvim-tree.notify" )
44local utils = require (" nvim-tree.utils" )
5- local view = require (" nvim-tree.view " )
5+ local core = require (" nvim-tree.core " )
66
77local M = {}
88
1919--- Get all windows in the current tabpage that aren't NvimTree.
2020--- @return table with valid win_ids
2121local function usable_win_ids ()
22+ local explorer = core .get_explorer ()
2223 local tabpage = vim .api .nvim_get_current_tabpage ()
2324 local win_ids = vim .api .nvim_tabpage_list_wins (tabpage )
24- local tree_winid = view . View :get_winnr (tabpage )
25+ local tree_winid = explorer and explorer . view :get_winnr (tabpage )
2526
2627 return vim .tbl_filter (function (id )
2728 local bufid = vim .api .nvim_win_get_buf (id )
198199
199200local function open_file_in_tab (filename )
200201 if M .quit_on_open then
201- view .View :close ()
202+ local explorer = core .get_explorer ()
203+ if explorer then
204+ explorer .view :close ()
205+ end
202206 end
203207 if M .relative_path then
204208 filename = utils .path_relative (filename , vim .fn .getcwd ())
208212
209213local function drop (filename )
210214 if M .quit_on_open then
211- view .View :close ()
215+ local explorer = core .get_explorer ()
216+ if explorer then
217+ explorer .view :close ()
218+ end
212219 end
213220 if M .relative_path then
214221 filename = utils .path_relative (filename , vim .fn .getcwd ())
218225
219226local function tab_drop (filename )
220227 if M .quit_on_open then
221- view .View :close ()
228+ local explorer = core .get_explorer ()
229+ if explorer then
230+ explorer .view :close ()
231+ end
222232 end
223233 if M .relative_path then
224234 filename = utils .path_relative (filename , vim .fn .getcwd ())
@@ -239,7 +249,10 @@ local function on_preview(buf_loaded)
239249 once = true ,
240250 })
241251 end
242- view .View :focus ()
252+ local explorer = core .get_explorer ()
253+ if explorer then
254+ explorer .view :focus ()
255+ end
243256end
244257
245258local function get_target_winid (mode )
@@ -279,6 +292,8 @@ local function set_current_win_no_autocmd(winid, autocmd)
279292end
280293
281294local function open_in_new_window (filename , mode )
295+ local explorer = core .get_explorer ()
296+
282297 if type (mode ) ~= " string" then
283298 mode = " "
284299 end
@@ -301,7 +316,11 @@ local function open_in_new_window(filename, mode)
301316 end , vim .api .nvim_list_wins ())
302317
303318 local create_new_window = # win_ids == 1 -- This implies that the nvim-tree window is the only one
304- local new_window_side = (view .View .side == " right" ) and " aboveleft" or " belowright"
319+
320+ local new_window_side = " belowright"
321+ if explorer and (explorer .view .side == " right" ) then
322+ new_window_side = " aboveleft"
323+ end
305324
306325 -- Target is invalid: create new window
307326 if not vim .tbl_contains (win_ids , target_winid ) then
@@ -333,7 +352,7 @@ local function open_in_new_window(filename, mode)
333352 end
334353 end
335354
336- if (mode == " preview" or mode == " preview_no_picker" ) and view . View .float .enable then
355+ if (mode == " preview" or mode == " preview_no_picker" ) and explorer and explorer . view .float .enable then
337356 -- ignore "WinLeave" autocmd on preview
338357 -- because the registered "WinLeave"
339358 -- will kill the floating window immediately
@@ -373,7 +392,12 @@ local function is_already_loaded(filename)
373392end
374393
375394local function edit_in_current_buf (filename )
376- require (" nvim-tree.view" ).View :abandon_current_window ()
395+ local explorer = core .get_explorer ()
396+
397+ if explorer then
398+ explorer .view :abandon_current_window ()
399+ end
400+
377401 if M .relative_path then
378402 filename = utils .path_relative (filename , vim .fn .getcwd ())
379403 end
384408--- @param filename string
385409--- @return nil
386410function M .fn (mode , filename )
411+ local explorer = core .get_explorer ()
412+
387413 if type (mode ) ~= " string" then
388414 mode = " "
389415 end
@@ -418,16 +444,16 @@ function M.fn(mode, filename)
418444 vim .bo .bufhidden = " "
419445 end
420446
421- if M .resize_window then
422- view . View :resize ()
447+ if M .resize_window and explorer then
448+ explorer . view :resize ()
423449 end
424450
425451 if mode == " preview" or mode == " preview_no_picker" then
426452 return on_preview (buf_loaded )
427453 end
428454
429- if M .quit_on_open then
430- view . View :close ()
455+ if M .quit_on_open and explorer then
456+ explorer . view :close ()
431457 end
432458end
433459
0 commit comments