mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 22:01:38 +00:00
TUI: Improve file completion display (fixes #280)
This commit is contained in:
parent
7e1b632596
commit
31f4a588fd
1 changed files with 15 additions and 4 deletions
|
|
@ -177,6 +177,18 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
|
||||||
const suggestions = this.getFileSuggestions(pathMatch);
|
const suggestions = this.getFileSuggestions(pathMatch);
|
||||||
if (suggestions.length === 0) return null;
|
if (suggestions.length === 0) return null;
|
||||||
|
|
||||||
|
// Check if we have an exact match that is a directory
|
||||||
|
// In that case, we might want to return suggestions for the directory content instead
|
||||||
|
// But only if the prefix ends with /
|
||||||
|
if (suggestions.length === 1 && suggestions[0]?.value === pathMatch && !pathMatch.endsWith("/")) {
|
||||||
|
// Exact match found (e.g. user typed "src" and "src/" is the only match)
|
||||||
|
// We still return it so user can select it and add /
|
||||||
|
return {
|
||||||
|
items: suggestions,
|
||||||
|
prefix: pathMatch,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: suggestions,
|
items: suggestions,
|
||||||
prefix: pathMatch,
|
prefix: pathMatch,
|
||||||
|
|
@ -434,15 +446,14 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
|
||||||
|
|
||||||
suggestions.push({
|
suggestions.push({
|
||||||
value: isDirectory ? `${relativePath}/` : relativePath,
|
value: isDirectory ? `${relativePath}/` : relativePath,
|
||||||
label: name,
|
label: name + (isDirectory ? "/" : ""),
|
||||||
description: isDirectory ? "directory" : "file",
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort directories first, then alphabetically
|
// Sort directories first, then alphabetically
|
||||||
suggestions.sort((a, b) => {
|
suggestions.sort((a, b) => {
|
||||||
const aIsDir = a.description === "directory";
|
const aIsDir = a.value.endsWith("/");
|
||||||
const bIsDir = b.description === "directory";
|
const bIsDir = b.value.endsWith("/");
|
||||||
if (aIsDir && !bIsDir) return -1;
|
if (aIsDir && !bIsDir) return -1;
|
||||||
if (!aIsDir && bIsDir) return 1;
|
if (!aIsDir && bIsDir) return 1;
|
||||||
return a.label.localeCompare(b.label);
|
return a.label.localeCompare(b.label);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue