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()
114
114
actions .root .change_dir .force_dirchange (bufname , true )
115
115
end
116
116
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
-
143
117
--- @return table
144
118
function M .get_config ()
145
119
return M .config
@@ -270,7 +244,10 @@ local function setup_autocommands(opts)
270
244
pattern = " NvimTree_*" ,
271
245
callback = function ()
272
246
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
274
251
end
275
252
end ,
276
253
})
Original file line number Diff line number Diff line change @@ -401,6 +401,27 @@ function Explorer:get_node_at_cursor()
401
401
return utils .get_nodes_by_line (self .nodes , core .get_nodes_starting_line ())[cursor [1 ]]
402
402
end
403
403
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
+
404
425
--- Api.tree.get_nodes
405
426
--- @return Node
406
427
function Explorer :get_nodes ()
You can’t perform that action at this time.
0 commit comments