Remove dot slash from suggested paths in `common.path_suggest`

When no `root` is specified and the initial `path` is empty, the initial 
`path` becomes `.`.
This results in returned files/dirs that are prepended with `./`.

Now, in that case, `./` is removed.
This commit is contained in:
Guldoman 2022-08-16 08:08:04 +02:00
parent 6ccc5f6dde
commit 4b4c54ba65
No known key found for this signature in database
GPG Key ID: EA928C8BDA1A8825
1 changed files with 8 additions and 0 deletions

View File

@ -152,11 +152,13 @@ function common.path_suggest(text, root)
root = root .. PATHSEP root = root .. PATHSEP
end end
local path, name = text:match("^(.-)([^/\\]*)$") local path, name = text:match("^(.-)([^/\\]*)$")
local clean_dotslash = false
-- ignore root if path is absolute -- ignore root if path is absolute
local is_absolute = common.is_absolute_path(text) local is_absolute = common.is_absolute_path(text)
if not is_absolute then if not is_absolute then
if path == "" then if path == "" then
path = root or "." path = root or "."
clean_dotslash = not root
else else
path = (root or "") .. path path = (root or "") .. path
end end
@ -180,6 +182,12 @@ function common.path_suggest(text, root)
if s == 1 then if s == 1 then
file = file:sub(e + 1) file = file:sub(e + 1)
end end
elseif clean_dotslash then
-- remove added dot slash
local s, e = file:find("." .. PATHSEP, nil, true)
if s == 1 then
file = file:sub(e + 1)
end
end end
if file:lower():find(text:lower(), nil, true) == 1 then if file:lower():find(text:lower(), nil, true) == 1 then
table.insert(res, file) table.insert(res, file)