From 6faa9087331494a4954560d550074d811d85b742 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 15 Sep 2022 20:35:05 +0530 Subject: [PATCH] And more corner cases --- tools/completion/files.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/completion/files.go b/tools/completion/files.go index 3072eb3d4..4b31b9c86 100644 --- a/tools/completion/files.go +++ b/tools/completion/files.go @@ -29,9 +29,12 @@ type CompleteFilesCallback func(completion_candidate, abspath string, d fs.DirEn func complete_files(prefix string, callback CompleteFilesCallback) error { base := prefix - if base != "~" && base != "./" { - if strings.Contains(base, string(os.PathSeparator)) { - base = filepath.Dir(base) + if base != "~" && base != "./" && base != "/" { + // cant use filepath.Dir() as it calls filepath.Clean() which + // can cause base to no longer match prefix + idx := strings.LastIndex(base, string(os.PathSeparator)) + if idx > 0 { + base = base[:idx] } else { base = "" }