@@ -2,6 +2,7 @@ local utils = require "nvim-tree.utils"
2
2
local view = require " nvim-tree.view"
3
3
local core = require " nvim-tree.core"
4
4
local lib = require " nvim-tree.lib"
5
+ local Iterator = require " nvim-tree.iterators.node-iterator"
5
6
6
7
local M = {}
7
8
@@ -27,26 +28,41 @@ function M.fn(direction)
27
28
return
28
29
end
29
30
31
+ local first , last , next , prev = nil , nil , nil , nil
32
+ local found = false
30
33
local parent = node .parent or core .get_explorer ()
31
- local parent_nodes = vim .tbl_filter (function (n )
32
- return not n .hidden
33
- end , parent .nodes )
34
+ Iterator .builder (parent .nodes )
35
+ :recursor (function ()
36
+ return nil
37
+ end )
38
+ :applier (function (n )
39
+ first = first or n
40
+ last = n
41
+ if n .absolute_path == node .absolute_path then
42
+ found = true
43
+ return
44
+ end
45
+ prev = not found and n or prev
46
+ if found and not next then
47
+ next = n
48
+ end
49
+ end )
50
+ :iterate ()
34
51
35
- local node_index = get_index_of (node , parent_nodes )
36
-
37
- local target_idx = node_index + direction
38
- if target_idx < 1 then
39
- target_idx = 1
40
- elseif target_idx > # parent_nodes then
41
- target_idx = # parent_nodes
52
+ local target_node
53
+ if direction == " first" then
54
+ target_node = first
55
+ elseif direction == " last" then
56
+ target_node = last
57
+ elseif direction == " next" then
58
+ target_node = next or first
59
+ else
60
+ target_node = prev or last
42
61
end
43
62
44
- local target_node = parent_nodes [target_idx ]
45
- local _ , line = utils .find_node (core .get_explorer ().nodes , function (n )
46
- return n .absolute_path == target_node .absolute_path
47
- end )
48
-
49
- view .set_cursor { line + 1 , 0 }
63
+ if target_node then
64
+ utils .focus_file (target_node .absolute_path )
65
+ end
50
66
end
51
67
end
52
68
0 commit comments