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