11local utils = require (" nvim-tree.utils" )
22local view = require (" nvim-tree.view" )
33local core = require (" nvim-tree.core" )
4- local lib = require (" nvim-tree.lib" )
54local diagnostics = require (" nvim-tree.diagnostics" )
65
76local DirectoryNode = require (" nvim-tree.node.directory" )
@@ -30,15 +29,11 @@ local function status_is_valid(node, what, skip_gitignored)
3029end
3130
3231--- Move to the next node that has a valid status. If none found, don't move.
32+ --- @param explorer Explorer
3333--- @param where string where to move (forwards or backwards )
3434--- @param what string type of status
3535--- @param skip_gitignored boolean default false
36- local function move (where , what , skip_gitignored )
37- local explorer = core .get_explorer ()
38- if not explorer then
39- return
40- end
41-
36+ local function move (explorer , where , what , skip_gitignored )
4237 local first_node_line = core .get_nodes_starting_line ()
4338 local nodes_by_line = utils .get_nodes_by_line (explorer .nodes , first_node_line )
4439 local iter_start , iter_end , iter_step , cur , first , nex
@@ -88,16 +83,17 @@ local function expand_node(node)
8883end
8984
9085--- Move to the next node recursively.
86+ --- @param explorer Explorer
9187--- @param what string type of status
9288--- @param skip_gitignored boolean default false
93- local function move_next_recursive (what , skip_gitignored )
89+ local function move_next_recursive (explorer , what , skip_gitignored )
9490 -- If the current node:
9591 -- * is a directory
9692 -- * and is not the root node
9793 -- * and has a git/diag status
9894 -- * and is not opened
9995 -- expand it.
100- local node_init = lib . get_node_at_cursor ()
96+ local node_init = explorer : get_node_at_cursor ()
10197 if not node_init then
10298 return
10399 end
@@ -110,9 +106,9 @@ local function move_next_recursive(what, skip_gitignored)
110106 node_init :expand_or_collapse (false )
111107 end
112108
113- move (" next" , what , skip_gitignored )
109+ move (explorer , " next" , what , skip_gitignored )
114110
115- local node_cur = lib . get_node_at_cursor ()
111+ local node_cur = explorer : get_node_at_cursor ()
116112 if not node_cur then
117113 return
118114 end
@@ -128,10 +124,10 @@ local function move_next_recursive(what, skip_gitignored)
128124 while is_dir and i < MAX_DEPTH do
129125 expand_node (node_cur )
130126
131- move (" next" , what , skip_gitignored )
127+ move (explorer , " next" , what , skip_gitignored )
132128
133129 -- Save current node.
134- node_cur = lib . get_node_at_cursor ()
130+ node_cur = explorer : get_node_at_cursor ()
135131 -- Update is_dir.
136132 if node_cur then
137133 is_dir = node_cur .nodes ~= nil
@@ -158,24 +154,25 @@ end
158154--- 4.4) Call a non-recursive prev.
159155--- 4.5) Save the current node and start back from 4.1.
160156---
157+ --- @param explorer Explorer
161158--- @param what string type of status
162159--- @param skip_gitignored boolean default false
163- local function move_prev_recursive (what , skip_gitignored )
160+ local function move_prev_recursive (explorer , what , skip_gitignored )
164161 local node_init , node_cur
165162
166163 -- 1)
167- node_init = lib . get_node_at_cursor ()
164+ node_init = explorer : get_node_at_cursor ()
168165 if node_init == nil then
169166 return
170167 end
171168
172169 -- 2)
173- move (" prev" , what , skip_gitignored )
170+ move (explorer , " prev" , what , skip_gitignored )
174171
175- node_cur = lib . get_node_at_cursor ()
172+ node_cur = explorer : get_node_at_cursor ()
176173 if node_cur == node_init .parent then
177174 -- 3)
178- move_prev_recursive (what , skip_gitignored )
175+ move_prev_recursive (explorer , what , skip_gitignored )
179176 else
180177 -- i is used to limit iterations.
181178 local i = 0
@@ -205,10 +202,10 @@ local function move_prev_recursive(what, skip_gitignored)
205202 end
206203
207204 -- 4.4)
208- move (" prev" , what , skip_gitignored )
205+ move (explorer , " prev" , what , skip_gitignored )
209206
210207 -- 4.5)
211- node_cur = lib . get_node_at_cursor ()
208+ node_cur = explorer : get_node_at_cursor ()
212209
213210 i = i + 1
214211 end
223220--- @return fun ()
224221function M .fn (opts )
225222 return function ()
223+ local explorer = core .get_explorer ()
224+ if not explorer then
225+ return
226+ end
227+
226228 local recurse = false
227229 local skip_gitignored = false
228230
@@ -236,14 +238,14 @@ function M.fn(opts)
236238 end
237239
238240 if not recurse then
239- move (opts .where , opts .what , skip_gitignored )
241+ move (explorer , opts .where , opts .what , skip_gitignored )
240242 return
241243 end
242244
243245 if opts .where == " next" then
244- move_next_recursive (opts .what , skip_gitignored )
246+ move_next_recursive (explorer , opts .what , skip_gitignored )
245247 elseif opts .where == " prev" then
246- move_prev_recursive (opts .what , skip_gitignored )
248+ move_prev_recursive (explorer , opts .what , skip_gitignored )
247249 end
248250 end
249251end
0 commit comments