@@ -461,8 +461,11 @@ M.get_appropriate_window = function(state)
461
461
-- use last window if possible
462
462
local suitable_window_found = false
463
463
local nt = require (" neo-tree" )
464
+ local ignore_ft = nt .config .open_files_do_not_replace_filetypes
465
+ local ignore = M .list_to_dict (ignore_ft )
466
+ ignore [" neo-tree" ] = true
464
467
if nt .config .open_files_in_last_window then
465
- local prior_window = nt .get_prior_window ()
468
+ local prior_window = nt .get_prior_window (ignore )
466
469
if prior_window > 0 then
467
470
local success = pcall (vim .api .nvim_set_current_win , prior_window )
468
471
if success then
@@ -480,13 +483,17 @@ M.get_appropriate_window = function(state)
480
483
end
481
484
local attempts = 0
482
485
while attempts < 5 and not suitable_window_found do
483
- if vim .bo .filetype == " neo-tree " or M .is_floating () then
486
+ if ignore [ vim .bo .filetype ] or M .is_floating () then
484
487
attempts = attempts + 1
485
488
vim .cmd (" wincmd w" )
486
489
else
487
490
suitable_window_found = true
488
491
end
489
492
end
493
+ if not suitable_window_found then
494
+ -- go back to the neotree window, this will forve it to open a new split
495
+ vim .api .nvim_set_current_win (current_window )
496
+ end
490
497
491
498
local winid = vim .api .nvim_get_current_win ()
492
499
local is_neo_tree_window = vim .bo .filetype == " neo-tree"
@@ -515,7 +522,8 @@ M.open_file = function(state, path, open_cmd, bufnr)
515
522
end
516
523
517
524
if M .truthy (path ) then
518
- local escaped_path = bufnr or vim .fn .fnameescape (path )
525
+ local escaped_path = vim .fn .fnameescape (path )
526
+ local bufnr_or_path = bufnr or escaped_path
519
527
local events = require (" neo-tree.events" )
520
528
local result = true
521
529
local err = nil
@@ -530,47 +538,58 @@ M.open_file = function(state, path, open_cmd, bufnr)
530
538
return
531
539
end
532
540
if state .current_position == " current" then
533
- result , err = pcall (vim .cmd , open_cmd .. " " .. escaped_path )
541
+ result , err = pcall (vim .cmd , open_cmd .. " " .. bufnr_or_path )
534
542
else
535
543
local winid , is_neo_tree_window = M .get_appropriate_window (state )
536
544
vim .api .nvim_set_current_win (winid )
537
545
-- TODO: make this configurable, see issue #43
538
546
if is_neo_tree_window then
539
- -- Neo-tree must be the only window, restore it's status as a sidebar
540
- local default_width = 40
541
- local width = M .get_value (state , " window.width" , default_width , false )
542
- local available_width = vim .api .nvim_win_get_width (0 )
543
- if type (width ) == " string" then
544
- if string.sub (width , - 1 ) == " %" then
545
- width = tonumber (string.sub (width , 1 , # width - 1 )) / 100
547
+ local width = vim .api .nvim_win_get_width (0 )
548
+ if width == vim .o .columns then
549
+ -- Neo-tree must be the only window, restore it's status as a sidebar
550
+ local default_width = 40
551
+ width = M .get_value (state , " window.width" , default_width , false )
552
+ local available_width = vim .api .nvim_win_get_width (0 )
553
+ if type (width ) == " string" then
554
+ if string.sub (width , - 1 ) == " %" then
555
+ width = tonumber (string.sub (width , 1 , # width - 1 )) / 100
556
+ else
557
+ width = tonumber (width )
558
+ end
559
+ width = math.floor (available_width * width )
560
+ elseif type (width ) == " function" then
561
+ width = width ()
562
+ if type (width ) ~= " number" then
563
+ width = default_width
564
+ else
565
+ width = math.floor (width )
566
+ end
567
+ elseif type (width ) == " number" then
568
+ width = math.floor (width )
546
569
else
547
- width = tonumber (width )
548
- end
549
- width = math.floor (available_width * width )
550
- elseif type (width ) == " function" then
551
- width = width ()
552
- if type (width ) ~= " number" then
553
570
width = default_width
554
- else
555
- width = math.floor (width )
556
571
end
557
- elseif type (width ) == " number" then
558
- width = math.floor (width )
559
- else
560
- width = default_width
561
572
end
562
- local nt = require ( " neo-tree " )
563
- local split_command = " vsplit "
573
+
574
+ local split_command = " vsplit"
564
575
-- respect window position in user config when Neo-tree is the only window
565
- if nt .config .window .position == " left" then
566
- split_command = " rightbelow vs "
567
- elseif nt .config .window .position == " right" then
568
- split_command = " leftabove vs "
576
+ if state .current_position == " left" then
577
+ split_command = " rightbelow vs"
578
+ elseif state .current_position == " right" then
579
+ split_command = " leftabove vs"
580
+ end
581
+ if path == " [No Name]" then
582
+ result , err = pcall (vim .cmd , split_command )
583
+ if result then
584
+ vim .cmd (" b" .. bufnr )
585
+ end
586
+ else
587
+ result , err = pcall (vim .cmd , split_command .. escaped_path )
569
588
end
570
- result , err = pcall ( vim . cmd , split_command .. escaped_path )
589
+
571
590
vim .api .nvim_win_set_width (winid , width )
572
591
else
573
- result , err = pcall (vim .cmd , open_cmd .. " " .. escaped_path )
592
+ result , err = pcall (vim .cmd , open_cmd .. " " .. bufnr_or_path )
574
593
end
575
594
end
576
595
if result or err == " Vim(edit):E325: ATTENTION" then
0 commit comments