2
2
local lib = require (" nvim-tree.lib" )
3
3
local notify = require (" nvim-tree.notify" )
4
4
local utils = require (" nvim-tree.utils" )
5
- local view = require (" nvim-tree.view " )
5
+ local core = require (" nvim-tree.core " )
6
6
7
7
local M = {}
8
8
19
19
--- Get all windows in the current tabpage that aren't NvimTree.
20
20
--- @return table with valid win_ids
21
21
local function usable_win_ids ()
22
+ local explorer = core .get_explorer ()
22
23
local tabpage = vim .api .nvim_get_current_tabpage ()
23
24
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 )
25
26
26
27
return vim .tbl_filter (function (id )
27
28
local bufid = vim .api .nvim_win_get_buf (id )
198
199
199
200
local function open_file_in_tab (filename )
200
201
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
202
206
end
203
207
if M .relative_path then
204
208
filename = utils .path_relative (filename , vim .fn .getcwd ())
208
212
209
213
local function drop (filename )
210
214
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
212
219
end
213
220
if M .relative_path then
214
221
filename = utils .path_relative (filename , vim .fn .getcwd ())
218
225
219
226
local function tab_drop (filename )
220
227
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
222
232
end
223
233
if M .relative_path then
224
234
filename = utils .path_relative (filename , vim .fn .getcwd ())
@@ -239,7 +249,10 @@ local function on_preview(buf_loaded)
239
249
once = true ,
240
250
})
241
251
end
242
- view .View :focus ()
252
+ local explorer = core .get_explorer ()
253
+ if explorer then
254
+ explorer .view :focus ()
255
+ end
243
256
end
244
257
245
258
local function get_target_winid (mode )
@@ -279,6 +292,8 @@ local function set_current_win_no_autocmd(winid, autocmd)
279
292
end
280
293
281
294
local function open_in_new_window (filename , mode )
295
+ local explorer = core .get_explorer ()
296
+
282
297
if type (mode ) ~= " string" then
283
298
mode = " "
284
299
end
@@ -301,7 +316,11 @@ local function open_in_new_window(filename, mode)
301
316
end , vim .api .nvim_list_wins ())
302
317
303
318
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
305
324
306
325
-- Target is invalid: create new window
307
326
if not vim .tbl_contains (win_ids , target_winid ) then
@@ -333,7 +352,7 @@ local function open_in_new_window(filename, mode)
333
352
end
334
353
end
335
354
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
337
356
-- ignore "WinLeave" autocmd on preview
338
357
-- because the registered "WinLeave"
339
358
-- will kill the floating window immediately
@@ -373,7 +392,12 @@ local function is_already_loaded(filename)
373
392
end
374
393
375
394
local 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
+
377
401
if M .relative_path then
378
402
filename = utils .path_relative (filename , vim .fn .getcwd ())
379
403
end
384
408
--- @param filename string
385
409
--- @return nil
386
410
function M .fn (mode , filename )
411
+ local explorer = core .get_explorer ()
412
+
387
413
if type (mode ) ~= " string" then
388
414
mode = " "
389
415
end
@@ -418,16 +444,16 @@ function M.fn(mode, filename)
418
444
vim .bo .bufhidden = " "
419
445
end
420
446
421
- if M .resize_window then
422
- view . View :resize ()
447
+ if M .resize_window and explorer then
448
+ explorer . view :resize ()
423
449
end
424
450
425
451
if mode == " preview" or mode == " preview_no_picker" then
426
452
return on_preview (buf_loaded )
427
453
end
428
454
429
- if M .quit_on_open then
430
- view . View :close ()
455
+ if M .quit_on_open and explorer then
456
+ explorer . view :close ()
431
457
end
432
458
end
433
459
0 commit comments