File tree 3 files changed +44
-5
lines changed 3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change
1
+ local lib = require " nvim-tree.lib"
2
+ local core = require " nvim-tree.core"
3
+ local utils = require " nvim-tree.utils"
1
4
local filters = require " nvim-tree.explorer.filters"
2
5
local reloaders = require " nvim-tree.actions.reloaders.reloaders"
3
6
4
7
local M = {}
5
8
9
+ local function reload ()
10
+ local node = lib .get_node_at_cursor ()
11
+ reloaders .reload_explorer ()
12
+ local explorer = core .get_explorer ()
13
+
14
+ if explorer == nil then
15
+ return
16
+ end
17
+
18
+ while node do
19
+ local found_node , _ = utils .find_node (explorer .nodes , function (node_ )
20
+ return node_ .absolute_path == node .absolute_path
21
+ end )
22
+
23
+ if found_node or node .parent == nil then
24
+ utils .focus_file (node .absolute_path )
25
+ break
26
+ end
27
+
28
+ node = node .parent
29
+ end
30
+ end
31
+
6
32
function M .custom ()
7
33
filters .config .filter_custom = not filters .config .filter_custom
8
- return reloaders . reload_explorer ()
34
+ reload ()
9
35
end
10
36
11
37
function M .git_ignored ()
12
38
filters .config .filter_git_ignored = not filters .config .filter_git_ignored
13
- return reloaders . reload_explorer ()
39
+ reload ()
14
40
end
15
41
16
42
function M .git_clean ()
17
43
filters .config .filter_git_clean = not filters .config .filter_git_clean
18
- return reloaders . reload_explorer ()
44
+ reload ()
19
45
end
20
46
21
47
function M .no_buffer ()
22
48
filters .config .filter_no_buffer = not filters .config .filter_no_buffer
23
- return reloaders . reload_explorer ()
49
+ reload ()
24
50
end
25
51
26
52
function M .dotfiles ()
27
53
filters .config .filter_dotfiles = not filters .config .filter_dotfiles
28
- return reloaders . reload_explorer ()
54
+ reload ()
29
55
end
30
56
31
57
return M
Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ local function create_overlay()
134
134
end
135
135
136
136
function M .start_filtering ()
137
+ view .View .live_filter .prev_focused_node = require (" nvim-tree.lib" ).get_node_at_cursor ()
137
138
M .filter = M .filter or " "
138
139
139
140
redraw ()
@@ -145,9 +146,18 @@ function M.start_filtering()
145
146
end
146
147
147
148
function M .clear_filter ()
149
+ local node = require (" nvim-tree.lib" ).get_node_at_cursor ()
150
+ local last_node = view .View .live_filter .prev_focused_node
151
+
148
152
M .filter = nil
149
153
reset_filter ()
150
154
redraw ()
155
+
156
+ if node then
157
+ utils .focus_file (node .absolute_path )
158
+ elseif last_node then
159
+ utils .focus_file (last_node .absolute_path )
160
+ end
151
161
end
152
162
153
163
function M .setup (opts )
Original file line number Diff line number Diff line change @@ -19,6 +19,9 @@ M.View = {
19
19
tabpages = {},
20
20
cursors = {},
21
21
hide_root_folder = false ,
22
+ live_filter = {
23
+ prev_focused_node = nil ,
24
+ },
22
25
winopts = {
23
26
relativenumber = false ,
24
27
number = false ,
You can’t perform that action at this time.
0 commit comments