File tree Expand file tree Collapse file tree 2 files changed +25
-27
lines changed Expand file tree Collapse file tree 2 files changed +25
-27
lines changed Original file line number Diff line number Diff line change @@ -114,32 +114,6 @@ function M.open_on_directory()
114114 actions .root .change_dir .force_dirchange (bufname , true )
115115end
116116
117- function M .place_cursor_on_node ()
118- local ok , search = pcall (vim .fn .searchcount )
119- if ok and search and search .exact_match == 1 then
120- return
121- end
122-
123- local explorer = core .get_explorer ()
124- if not explorer then
125- return
126- end
127-
128- local node = explorer :get_node_at_cursor ()
129- if not node or node .name == " .." then
130- return
131- end
132- node = node :get_parent_of_group () or node
133-
134- local line = vim .api .nvim_get_current_line ()
135- local cursor = vim .api .nvim_win_get_cursor (0 )
136- local idx = vim .fn .stridx (line , node .name )
137-
138- if idx >= 0 then
139- vim .api .nvim_win_set_cursor (0 , { cursor [1 ], idx })
140- end
141- end
142-
143117--- @return table
144118function M .get_config ()
145119 return M .config
@@ -270,7 +244,10 @@ local function setup_autocommands(opts)
270244 pattern = " NvimTree_*" ,
271245 callback = function ()
272246 if utils .is_nvim_tree_buf (0 ) then
273- M .place_cursor_on_node ()
247+ local explorer = core .get_explorer ()
248+ if explorer then
249+ explorer :place_cursor_on_node ()
250+ end
274251 end
275252 end ,
276253 })
Original file line number Diff line number Diff line change @@ -401,6 +401,27 @@ function Explorer:get_node_at_cursor()
401401 return utils .get_nodes_by_line (self .nodes , core .get_nodes_starting_line ())[cursor [1 ]]
402402end
403403
404+ function Explorer :place_cursor_on_node ()
405+ local ok , search = pcall (vim .fn .searchcount )
406+ if ok and search and search .exact_match == 1 then
407+ return
408+ end
409+
410+ local node = self :get_node_at_cursor ()
411+ if not node or node .name == " .." then
412+ return
413+ end
414+ node = node :get_parent_of_group () or node
415+
416+ local line = vim .api .nvim_get_current_line ()
417+ local cursor = vim .api .nvim_win_get_cursor (0 )
418+ local idx = vim .fn .stridx (line , node .name )
419+
420+ if idx >= 0 then
421+ vim .api .nvim_win_set_cursor (0 , { cursor [1 ], idx })
422+ end
423+ end
424+
404425--- Api.tree.get_nodes
405426--- @return Node
406427function Explorer :get_nodes ()
You can’t perform that action at this time.
0 commit comments