Merge branch 'fix-root-path-completion' of https://github.com/devangpratap/kitty
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

This commit is contained in:
Kovid Goyal 2026-09-15 22:05:05 +05:30
commit 0c19dbfa8f
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 1 deletions

View file

@ -65,7 +65,7 @@ func CompleteFiles(prefix string, callback func(*FileEntry), cwd string) error {
joinable_prefix = prefix
} else {
idx := strings.LastIndex(prefix, utils.Sep)
if idx > 0 {
if idx > -1 {
joinable_prefix = prefix[:idx+1]
base_dir = filepath.Dir(location)
}

View file

@ -89,6 +89,18 @@ func TestCompleteFiles(t *testing.T) {
test_candidates("odir/f", "odir/four.txt")
test_candidates("x")
// a prefix whose only separator is the leading one, such as /us
if entries, err := os.ReadDir(utils.Sep); err == nil && len(entries) > 0 {
name := entries[0].Name()
prefix := utils.Sep + name[:1]
found := false
CompleteFiles(prefix, func(entry *FileEntry) {
found = found || strings.TrimSuffix(entry.CompletionCandidate, utils.Sep) == utils.Sep+name
}, "")
if !found {
t.Fatalf("Did not get %#v as a completion candidate for prefix: %#v", utils.Sep+name, prefix)
}
}
}
func TestCompleteExecutables(t *testing.T) {