@@ -461,8 +461,11 @@ M.get_appropriate_window = function(state)
461461 -- use last window if possible
462462 local suitable_window_found = false
463463 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
464467 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 )
466469 if prior_window > 0 then
467470 local success = pcall (vim .api .nvim_set_current_win , prior_window )
468471 if success then
@@ -480,13 +483,17 @@ M.get_appropriate_window = function(state)
480483 end
481484 local attempts = 0
482485 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
484487 attempts = attempts + 1
485488 vim .cmd (" wincmd w" )
486489 else
487490 suitable_window_found = true
488491 end
489492 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
490497
491498 local winid = vim .api .nvim_get_current_win ()
492499 local is_neo_tree_window = vim .bo .filetype == " neo-tree"
@@ -515,7 +522,8 @@ M.open_file = function(state, path, open_cmd, bufnr)
515522 end
516523
517524 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
519527 local events = require (" neo-tree.events" )
520528 local result = true
521529 local err = nil
@@ -530,47 +538,58 @@ M.open_file = function(state, path, open_cmd, bufnr)
530538 return
531539 end
532540 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 )
534542 else
535543 local winid , is_neo_tree_window = M .get_appropriate_window (state )
536544 vim .api .nvim_set_current_win (winid )
537545 -- TODO: make this configurable, see issue #43
538546 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 )
546569 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
553570 width = default_width
554- else
555- width = math.floor (width )
556571 end
557- elseif type (width ) == " number" then
558- width = math.floor (width )
559- else
560- width = default_width
561572 end
562- local nt = require ( " neo-tree " )
563- local split_command = " vsplit "
573+
574+ local split_command = " vsplit"
564575 -- 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 )
569588 end
570- result , err = pcall ( vim . cmd , split_command .. escaped_path )
589+
571590 vim .api .nvim_win_set_width (winid , width )
572591 else
573- result , err = pcall (vim .cmd , open_cmd .. " " .. escaped_path )
592+ result , err = pcall (vim .cmd , open_cmd .. " " .. bufnr_or_path )
574593 end
575594 end
576595 if result or err == " Vim(edit):E325: ATTENTION" then
0 commit comments