@@ -151,7 +151,7 @@ function Explorer:create_autocmds()
151151 pattern = " NvimTree_*" ,
152152 callback = function ()
153153 if utils .is_nvim_tree_buf (0 ) then
154- if vim .fn .getcwd () ~= core . get_cwd () or (self .opts .reload_on_bufenter and not self .opts .filesystem_watchers .enable ) then
154+ if vim .fn .getcwd () ~= self . absolute_path or (self .opts .reload_on_bufenter and not self .opts .filesystem_watchers .enable ) then
155155 self :reload_explorer ()
156156 end
157157 end
@@ -528,7 +528,7 @@ function Explorer:get_node_at_cursor()
528528 return
529529 end
530530
531- if cursor [1 ] == 1 and view .is_root_folder_visible (core . get_cwd () ) then
531+ if cursor [1 ] == 1 and view .is_root_folder_visible (self . absolute_path ) then
532532 return self
533533 end
534534
@@ -669,7 +669,7 @@ function Explorer:dir_up(node)
669669 if not node or node .name == " .." then
670670 self :change_dir (" .." )
671671 else
672- local cwd = core . get_cwd ()
672+ local cwd = self . absolute_path
673673 if cwd == nil then
674674 return
675675 end
@@ -686,18 +686,20 @@ function Explorer:get_nodes()
686686 return self :clone ()
687687end
688688
689+ --- @private
689690--- @param new_tabpage integer
690691--- @return boolean
691692function Explorer :is_window_event (new_tabpage )
692693 local is_event_scope_window = vim .v .event .scope == " window" or vim .v .event .changed_window or false
693694 return is_event_scope_window and new_tabpage == self .current_tab
694695end
695696
697+ --- @private
696698--- @param name string
697699--- @return string | nil
698700function Explorer :clean_input_cwd (name )
699701 name = vim .fn .fnameescape (name )
700- local cwd = core . get_cwd ()
702+ local cwd = self . absolute_path
701703 if cwd == nil then
702704 return
703705 end
@@ -709,65 +711,54 @@ function Explorer:clean_input_cwd(name)
709711 end
710712end
711713
714+ --- @private
712715--- @param foldername string
713716--- @return boolean
714717function Explorer :prevent_cwd_change (foldername )
715- local is_same_cwd = foldername == core . get_cwd ()
718+ local is_same_cwd = foldername == self . absolute_path
716719 local is_restricted_above = config .restrict_above_cwd and foldername < vim .fn .getcwd (- 1 , - 1 )
717720 return is_same_cwd or is_restricted_above
718721end
719722
720- --- @param f function
721- --- @return fun ( foldername : string , should_open_view : boolean | nil )
722- function Explorer :add_profiling_to (f )
723- return function (foldername , should_open_view )
724- local profile = log .profile_start (" change dir %s" , foldername )
725- f (foldername , should_open_view )
726- log .profile_end (profile )
727- end
728- end
729-
723+ --- @private
730724--- @return boolean
731725function Explorer :should_change_dir ()
732726 return config .enable and vim .tbl_isempty (vim .v .event )
733727end
734728
729+ --- @private
735730--- @param global boolean
736731--- @param path string
737732function Explorer :cd (global , path )
738733 vim .cmd ((global and " cd " or " lcd " ) .. vim .fn .fnameescape (path ))
739734end
740735
741- function Explorer :force_dirchange (folder_name , with_open )
742- local fn = self :add_profiling_to (function (foldername , should_open_view )
743- local valid_dir = vim .fn .isdirectory (foldername ) == 1 -- prevent problems on non existing dirs
744- if valid_dir then
745- if self :should_change_dir () then
746- self :cd (config .global , foldername )
747- end
748- core .init (foldername )
736+ --- @private
737+ --- @param foldername string
738+ --- @param should_open_view boolean | nil
739+ function Explorer :force_dirchange (foldername , should_open_view )
740+ local profile = log .profile_start (" change dir %s" , foldername )
741+
742+ local valid_dir = vim .fn .isdirectory (foldername ) == 1 -- prevent problems on non existing dirs
743+ if valid_dir then
744+ if self :should_change_dir () then
745+ self :cd (config .global , foldername )
749746 end
747+ core .init (foldername )
748+ end
750749
751- if should_open_view then
752- require (" nvim-tree.lib" ).open ()
753- else
754- local explorer = core .get_explorer ()
755- if explorer then
756- explorer .renderer :draw ()
757- end
758- end
759- end )
750+ if should_open_view then
751+ require (" nvim-tree.lib" ).open ()
752+ else
753+ self .renderer :draw ()
754+ end
760755
761- fn ( folder_name , with_open )
756+ log . profile_end ( profile )
762757end
763758
764759--- @param input_cwd string
765760--- @param with_open boolean | nil
766761function Explorer :change_dir (input_cwd , with_open )
767- if not core .get_explorer () then
768- return
769- end
770-
771762 local new_tabpage = vim .api .nvim_get_current_tabpage ()
772763 if self :is_window_event (new_tabpage ) then
773764 return
0 commit comments