File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,16 @@ local function setup_autocommands(opts)
335
335
-- reset highlights when colorscheme is changed
336
336
create_nvim_tree_autocmd (" ColorScheme" , { callback = M .reset_highlight })
337
337
338
+ -- prevent new opened file from opening in the same window as nvim-tree
339
+ create_nvim_tree_autocmd (" BufWipeout" , {
340
+ pattern = " NvimTree_*" ,
341
+ callback = function ()
342
+ if vim .bo .filetype == " NvimTree" then
343
+ view ._prevent_buffer_override ()
344
+ end
345
+ end ,
346
+ })
347
+
338
348
local has_watchers = opts .filesystem_watchers .enable
339
349
340
350
if opts .auto_reload_on_write and not has_watchers then
@@ -369,12 +379,6 @@ local function setup_autocommands(opts)
369
379
})
370
380
end
371
381
372
- if not opts .actions .open_file .quit_on_open then
373
- create_nvim_tree_autocmd (" BufWipeout" , { pattern = " NvimTree_*" , callback = view ._prevent_buffer_override })
374
- else
375
- create_nvim_tree_autocmd (" BufWipeout" , { pattern = " NvimTree_*" , callback = view .abandon_current_window })
376
- end
377
-
378
382
if opts .hijack_directories .enable then
379
383
create_nvim_tree_autocmd ({ " BufEnter" , " BufNewFile" }, { callback = M .open_on_directory })
380
384
end
Original file line number Diff line number Diff line change @@ -399,8 +399,10 @@ function M._prevent_buffer_override()
399
399
-- Otherwise the curwin/curbuf would match the view buffer and the view window.
400
400
vim .schedule (function ()
401
401
local curwin = a .nvim_get_current_win ()
402
+ local curwinconfig = a .nvim_win_get_config (curwin )
402
403
local curbuf = a .nvim_win_get_buf (curwin )
403
404
local bufname = a .nvim_buf_get_name (curbuf )
405
+
404
406
if not bufname :match " NvimTree" then
405
407
for i , tabpage in ipairs (M .View .tabpages ) do
406
408
if tabpage .winnr == view_winnr then
@@ -420,7 +422,14 @@ function M._prevent_buffer_override()
420
422
M .open { focus_tree = false }
421
423
require (" nvim-tree.renderer" ).draw ()
422
424
pcall (a .nvim_win_close , curwin , { force = true })
423
- require (" nvim-tree.actions.node.open-file" ).fn (" edit" , bufname )
425
+
426
+ -- to handle opening a file using :e when nvim-tree is on floating mode
427
+ -- falling back to the current window instead of creating a new one
428
+ if curwinconfig .relative ~= " " then
429
+ require (" nvim-tree.actions.node.open-file" ).fn (" edit_in_place" , bufname )
430
+ else
431
+ require (" nvim-tree.actions.node.open-file" ).fn (" edit" , bufname )
432
+ end
424
433
end )
425
434
end
426
435
You can’t perform that action at this time.
0 commit comments