@@ -129,8 +129,6 @@ M.execute = function(args)
129
129
args .dir = args .dir :sub (1 , - 2 )
130
130
end
131
131
path_changed = state .path ~= args .dir
132
- else
133
- args .dir = state .path
134
132
end
135
133
136
134
-- Handle setting git ref
@@ -156,11 +154,13 @@ M.execute = function(args)
156
154
-- manager.close(args.source)
157
155
-- end
158
156
if do_reveal then
159
- args .reveal_file = utils .normalize_path (args .reveal_file )
160
157
handle_reveal (args , state )
161
- else
162
- do_show_or_focus (args , state , force_navigate )
158
+ return
159
+ end
160
+ if not args .dir then
161
+ args .dir = state .path
163
162
end
163
+ do_show_or_focus (args , state , force_navigate )
164
164
end
165
165
166
166
--- Parses and executes the command line. Use execute(args) instead.
@@ -207,30 +207,38 @@ do_show_or_focus = function(args, state, force_navigate)
207
207
end
208
208
209
209
handle_reveal = function (args , state )
210
+ args .reveal_file = utils .normalize_path (args .reveal_file )
210
211
-- Deal with cwd if we need to
211
- local cwd = state .path
212
- local path = args .reveal_file
213
- if cwd == nil then
214
- cwd = manager .get_cwd (state )
215
- end
216
- if args .reveal_force_cwd and not utils .is_subpath (cwd , path ) then
217
- args .dir , _ = utils .split_path (path )
212
+ local cwd = args .dir or state .path or manager .get_cwd (state )
213
+ if utils .is_subpath (cwd , args .reveal_file ) then
214
+ args .dir = cwd
218
215
do_show_or_focus (args , state , true )
219
216
return
220
- elseif not utils .is_subpath (cwd , path ) then
221
- -- force was not specified, so we need to ask the user
222
- cwd , _ = utils .split_path (path )
223
- inputs .confirm (" File not in cwd. Change cwd to " .. cwd .. " ?" , function (response )
224
- if response == true then
225
- args .dir = cwd
226
- else
227
- args .reveal_file = nil
228
- end
229
- do_show_or_focus (args , state , true )
230
- end )
217
+ end
218
+
219
+ local reveal_file_parent , _ = utils .split_path (args .reveal_file ) --[[ @as string]]
220
+ if args .reveal_force_cwd then
221
+ args .dir = reveal_file_parent
222
+ do_show_or_focus (args , state , true )
231
223
return
232
- else
224
+ end
225
+
226
+ -- if dir doesn't have the reveal_file, ignore the reveal_file
227
+ if args .dir then
228
+ args .reveal_file = nil
233
229
do_show_or_focus (args , state , true )
230
+ return
234
231
end
232
+
233
+ -- force was not specified and the file does not belong to cwd, so we need to ask the user
234
+ inputs .confirm (" File not in cwd. Change cwd to " .. reveal_file_parent .. " ?" , function (response )
235
+ if response == true then
236
+ args .dir = reveal_file_parent
237
+ else
238
+ args .reveal_file = nil
239
+ end
240
+ do_show_or_focus (args , state , true )
241
+ end )
235
242
end
243
+
236
244
return M
0 commit comments