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"
6
5
7
6
local M = {}
8
7
19
18
--- Get all windows in the current tabpage that aren't NvimTree.
20
19
--- @return table with valid win_ids
21
20
local function usable_win_ids ()
21
+ local explorer = require " nvim-tree.core" .get_explorer ()
22
+
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 . 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 )
188
189
189
190
local function open_file_in_tab (filename )
190
191
if M .quit_on_open then
191
- view .close ()
192
+ local explorer = require " nvim-tree.core" .get_explorer ()
193
+ if explorer then
194
+ explorer .view :close ()
195
+ end
192
196
end
193
197
if M .relative_path then
194
198
filename = utils .path_relative (filename , vim .fn .getcwd ())
198
202
199
203
local function drop (filename )
200
204
if M .quit_on_open then
201
- view .close ()
205
+ local explorer = require " nvim-tree.core" .get_explorer ()
206
+ if explorer then
207
+ explorer .view :close ()
208
+ end
202
209
end
203
210
if M .relative_path then
204
211
filename = utils .path_relative (filename , vim .fn .getcwd ())
208
215
209
216
local function tab_drop (filename )
210
217
if M .quit_on_open then
211
- view .close ()
218
+ local explorer = require " nvim-tree.core" .get_explorer ()
219
+ if explorer then
220
+ explorer .view :close ()
221
+ end
212
222
end
213
223
if M .relative_path then
214
224
filename = utils .path_relative (filename , vim .fn .getcwd ())
@@ -229,7 +239,10 @@ local function on_preview(buf_loaded)
229
239
once = true ,
230
240
})
231
241
end
232
- view .focus ()
242
+ local explorer = require " nvim-tree.core" .get_explorer ()
243
+ if explorer then
244
+ explorer .view :focus ()
245
+ end
233
246
end
234
247
235
248
local function get_target_winid (mode )
@@ -287,7 +300,8 @@ local function open_in_new_window(filename, mode)
287
300
end , vim .api .nvim_list_wins ())
288
301
289
302
local create_new_window = # win_ids == 1 -- This implies that the nvim-tree window is the only one
290
- local new_window_side = (view .View .side == " right" ) and " aboveleft" or " belowright"
303
+ local explorer = require " nvim-tree.core" .get_explorer ()
304
+ local new_window_side = (explorer and view .View .side == " right" ) and " aboveleft" or " belowright"
291
305
292
306
-- Target is invalid: create new window
293
307
if not vim .tbl_contains (win_ids , target_winid ) then
@@ -319,7 +333,7 @@ local function open_in_new_window(filename, mode)
319
333
end
320
334
end
321
335
322
- if (mode == " preview" or mode == " preview_no_picker" ) and view .View .float .enable then
336
+ if (mode == " preview" or mode == " preview_no_picker" ) and explorer and explorer . view .View .float .enable then
323
337
-- ignore "WinLeave" autocmd on preview
324
338
-- because the registered "WinLeave"
325
339
-- will kill the floating window immediately
@@ -359,7 +373,10 @@ local function is_already_loaded(filename)
359
373
end
360
374
361
375
local function edit_in_current_buf (filename )
362
- require (" nvim-tree.view" ).abandon_current_window ()
376
+ local explorer = require " nvim-tree.core" .get_explorer ()
377
+ if explorer then
378
+ explorer .view :abandon_current_window ()
379
+ end
363
380
if M .relative_path then
364
381
filename = utils .path_relative (filename , vim .fn .getcwd ())
365
382
end
@@ -404,15 +421,21 @@ function M.fn(mode, filename)
404
421
end
405
422
406
423
if M .resize_window then
407
- view .resize ()
424
+ local explorer = require " nvim-tree.core" .get_explorer ()
425
+ if explorer then
426
+ explorer .view :resize ()
427
+ end
408
428
end
409
429
410
430
if mode == " preview" or mode == " preview_no_picker" then
411
431
return on_preview (buf_loaded )
412
432
end
413
433
414
434
if M .quit_on_open then
415
- view .close ()
435
+ local explorer = require " nvim-tree.core" .get_explorer ()
436
+ if explorer then
437
+ explorer .view :close ()
438
+ end
416
439
end
417
440
end
418
441
0 commit comments