22local lib = require (" nvim-tree.lib" )
33local notify = require (" nvim-tree.notify" )
44local utils = require (" nvim-tree.utils" )
5- local core = require (" nvim-tree.core" )
65local full_name = require (" nvim-tree.renderer.components.full-name" )
6+ local view = require (" nvim-tree.view" )
77
88local M = {}
99
2020--- Get all windows in the current tabpage that aren't NvimTree.
2121--- @return table with valid win_ids
2222local function usable_win_ids ()
23- local explorer = core .get_explorer ()
2423 local tabpage = vim .api .nvim_get_current_tabpage ()
2524 local win_ids = vim .api .nvim_tabpage_list_wins (tabpage )
26- local tree_winid = explorer and explorer . view : get_winid (tabpage )
25+ local tree_winid = view . get_winnr (tabpage )
2726
2827 return vim .tbl_filter (function (id )
2928 local bufid = vim .api .nvim_win_get_buf (id )
194193
195194local function open_file_in_tab (filename )
196195 if M .quit_on_open then
197- local explorer = core .get_explorer ()
198- if explorer then
199- explorer .view :close ()
200- end
196+ view .close ()
201197 end
202198 if M .relative_path then
203199 filename = utils .path_relative (filename , vim .fn .getcwd ())
207203
208204local function drop (filename )
209205 if M .quit_on_open then
210- local explorer = core .get_explorer ()
211- if explorer then
212- explorer .view :close ()
213- end
206+ view .close ()
214207 end
215208 if M .relative_path then
216209 filename = utils .path_relative (filename , vim .fn .getcwd ())
220213
221214local function tab_drop (filename )
222215 if M .quit_on_open then
223- local explorer = core .get_explorer ()
224- if explorer then
225- explorer .view :close ()
226- end
216+ view .close ()
227217 end
228218 if M .relative_path then
229219 filename = utils .path_relative (filename , vim .fn .getcwd ())
@@ -244,10 +234,7 @@ local function on_preview(buf_loaded)
244234 once = true ,
245235 })
246236 end
247- local explorer = core .get_explorer ()
248- if explorer then
249- explorer .view :focus ()
250- end
237+ view .focus ()
251238end
252239
253240local function get_target_winid (mode )
@@ -292,8 +279,6 @@ local function set_current_win_no_autocmd(winid, autocmd)
292279end
293280
294281local function open_in_new_window (filename , mode )
295- local explorer = core .get_explorer ()
296-
297282 if type (mode ) ~= " string" then
298283 mode = " "
299284 end
@@ -316,11 +301,7 @@ local function open_in_new_window(filename, mode)
316301 end , vim .api .nvim_list_wins ())
317302
318303 local create_new_window = # win_ids == 1 -- This implies that the nvim-tree window is the only one
319-
320- local new_window_side = " belowright"
321- if explorer and (explorer .view .side == " right" ) then
322- new_window_side = " aboveleft"
323- end
304+ local new_window_side = (view .View .side == " right" ) and " aboveleft" or " belowright"
324305
325306 -- Target is invalid: create new window
326307 if not vim .tbl_contains (win_ids , target_winid ) then
@@ -352,7 +333,7 @@ local function open_in_new_window(filename, mode)
352333 end
353334 end
354335
355- if (mode == " preview" or mode == " preview_no_picker" ) and explorer and explorer . opts . view .float .enable then
336+ if (mode == " preview" or mode == " preview_no_picker" ) and view . View .float .enable then
356337 -- ignore "WinLeave" autocmd on preview
357338 -- because the registered "WinLeave"
358339 -- will kill the floating window immediately
@@ -392,12 +373,7 @@ local function is_already_loaded(filename)
392373end
393374
394375local function edit_in_current_buf (filename )
395- local explorer = core .get_explorer ()
396-
397- if explorer then
398- explorer .view :abandon_current_window ()
399- end
400-
376+ require (" nvim-tree.view" ).abandon_current_window ()
401377 if M .relative_path then
402378 filename = utils .path_relative (filename , vim .fn .getcwd ())
403379 end
408384--- @param filename string
409385--- @return nil
410386function M .fn (mode , filename )
411- local explorer = core .get_explorer ()
412-
413387 if type (mode ) ~= " string" then
414388 mode = " "
415389 end
@@ -444,16 +418,16 @@ function M.fn(mode, filename)
444418 vim .bo .bufhidden = " "
445419 end
446420
447- if M .resize_window and explorer then
448- explorer . view : resize ()
421+ if M .resize_window then
422+ view . resize ()
449423 end
450424
451425 if mode == " preview" or mode == " preview_no_picker" then
452426 return on_preview (buf_loaded )
453427 end
454428
455- if M .quit_on_open and explorer then
456- explorer . view : close ()
429+ if M .quit_on_open then
430+ view . close ()
457431 end
458432end
459433
0 commit comments