File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ M.reveal_current_file = function(source_name)
258
258
if cwd == nil then
259
259
cwd = vim .fn .getcwd ()
260
260
end
261
- if string.sub ( path , 1 , string.len (cwd )) ~= cwd then
261
+ if not utils . is_subpath (cwd , path ) then
262
262
cwd , _ = utils .split_path (path )
263
263
inputs .confirm (" File not in cwd. Change cwd to " .. cwd .. " ?" , function (response )
264
264
if response == true then
Original file line number Diff line number Diff line change @@ -274,6 +274,27 @@ if M.is_windows == true then
274
274
M .path_separator = " \\ "
275
275
end
276
276
277
+ --- Normalize a path, to avoid errors when comparing paths.
278
+ --- @param path string The path to be normalize.
279
+ --- @return string string The normalized path.
280
+ M .normalize_path = function (path )
281
+ if M .is_windows then
282
+ -- normalize the drive letter to uppercase
283
+ path = path :sub (1 , 1 ):upper () .. path :sub (2 )
284
+ end
285
+ return path
286
+ end
287
+
288
+ --- Check if a path is a subpath of another.
289
+ -- @param base string The base path.
290
+ -- @param path string The path to check is a subpath.
291
+ -- @return boolean boolean True if it is a subpath, false otherwise.
292
+ M .is_subpath = function (base , path )
293
+ base = M .normalize_path (base )
294
+ path = M .normalize_path (path )
295
+ return string.sub (path , 1 , string.len (base )) == base
296
+ end
297
+
277
298
--- Split string into a table of strings using a separator.
278
299
--- @param inputString string The string to split.
279
300
--- @param sep string The separator to use.
You can’t perform that action at this time.
0 commit comments