@@ -53,6 +53,7 @@ M.get_state = function(source_name, tabnr)
53
53
end
54
54
state = utils .table_copy (sd .default_config )
55
55
state .tabnr = tabnr
56
+ state .dirty = true
56
57
sd .state_by_tab [tabnr ] = state
57
58
return state
58
59
end
@@ -146,6 +147,9 @@ M.dir_changed = function(source_name)
146
147
end
147
148
if state .path and renderer .window_exists (state ) then
148
149
M .navigate (source_name , cwd )
150
+ else
151
+ state .path = cwd
152
+ state .dirty = true
149
153
end
150
154
end
151
155
@@ -183,7 +187,7 @@ M.focus = function(source_name, path_to_reveal, callback)
183
187
if path_to_reveal then
184
188
M .navigate (source_name , state .path , path_to_reveal , callback )
185
189
else
186
- if renderer .window_exists (state ) then
190
+ if not state . dirty and renderer .window_exists (state ) then
187
191
vim .api .nvim_set_current_win (state .winid )
188
192
else
189
193
M .navigate (source_name , state .path , nil , callback )
@@ -200,14 +204,8 @@ M.navigate = function(source_name, path, path_to_reveal, callback)
200
204
require (" neo-tree.sources." .. source_name ).navigate (path , path_to_reveal , callback )
201
205
end
202
206
203
- M .reveal_current_file = function (source_name , toggle_if_open )
207
+ M .reveal_current_file = function (source_name )
204
208
log .trace (" Revealing current file" )
205
- if toggle_if_open then
206
- if M .close () then
207
- -- It was open, and now it's not.
208
- return
209
- end
210
- end
211
209
local state = M .get_state (source_name )
212
210
require (" neo-tree" ).close_all_except (source_name )
213
211
local path = M .get_path_to_reveal ()
@@ -225,6 +223,8 @@ M.reveal_current_file = function(source_name, toggle_if_open)
225
223
if response == true then
226
224
state .path = cwd
227
225
M .focus (path )
226
+ else
227
+ M .focus ()
228
228
end
229
229
end )
230
230
return
@@ -249,12 +249,16 @@ end
249
249
--- Refreshes the tree by scanning the filesystem again.
250
250
M .refresh = function (source_name , callback )
251
251
log .trace (source_name , " refresh" )
252
- local state = M .get_state (source_name )
253
- if state .path and renderer .window_exists (state ) then
254
- if type (callback ) ~= " function" then
255
- callback = nil
252
+ local sd = get_source_data (source_name )
253
+ for _ , state in pairs (sd .state_by_tab ) do
254
+ if state .path and renderer .window_exists (state ) then
255
+ if type (callback ) ~= " function" then
256
+ callback = nil
257
+ end
258
+ M .navigate (source_name , state .path , nil , callback )
259
+ else
260
+ state .dirty = true
256
261
end
257
- M .navigate (source_name , state .path , nil , callback )
258
262
end
259
263
end
260
264
@@ -309,11 +313,15 @@ M.setup = function(source_name, config, global_config)
309
313
end
310
314
end
311
315
312
- --- Opens the tree and displays the current path or cwd.
313
- --- @param callback function Callback to call after the items are loaded.
314
- M .show = function (source_name , callback )
316
+ --- Opens the tree and displays the current path or cwd, without focusing it.
317
+ M .show = function (source_name )
315
318
local state = M .get_state (source_name )
316
- M .navigate (source_name , state .path , nil , callback )
319
+ if not renderer .window_exists (state ) then
320
+ local current_win = vim .api .nvim_get_current_win ()
321
+ M .navigate (source_name , state .path , nil , function ()
322
+ vim .api .nvim_set_current_win (current_win )
323
+ end )
324
+ end
317
325
end
318
326
319
327
return M
0 commit comments