From 30ce8ba59bb252b59bd55cfbe7260fbd5f5032ef Mon Sep 17 00:00:00 2001 From: Abhishek B R Date: Tue, 17 Nov 2026 10:30:07 +0530 Subject: [PATCH] fix(client-runtime): Tab completes a folder name when the list shows fuzzy matches Since the add-project folder list started showing substring and fuzzy matches, Tab took the common prefix of every visible folder, so any non-prefix match made it do nothing. Tab now completes from the folders whose names start with what was typed, as it did before. --- .../client-runtime/src/state/filesystem.test.ts | 12 ++++++++++++ packages/client-runtime/src/state/filesystem.ts | 13 ++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/client-runtime/src/state/filesystem.test.ts b/packages/client-runtime/src/state/filesystem.test.ts index 3234454bc7a8c..f0c87f7c7f447 100644 --- a/packages/client-runtime/src/state/filesystem.test.ts +++ b/packages/client-runtime/src/state/filesystem.test.ts @@ -107,6 +107,18 @@ describe("filesystem browse model", () => { isComplete: false, }); expect(getFilesystemBrowseTabCompletion([], "x")).toBeNull(); + // The list also shows substring and fuzzy matches; Tab completes only the typed name. + expect(getFilesystemBrowseTabCompletion([entry("t3code"), entry("my-t3code")], "t3")).toEqual({ + name: "t3code", + isComplete: true, + }); + expect( + getFilesystemBrowseTabCompletion( + [entry("OpenSourced"), entry("OpenAI"), entry("reopen"), entry("photos")], + "op", + ), + ).toEqual({ name: "Open", isComplete: false }); + expect(getFilesystemBrowseTabCompletion([entry("t3code")], "tcd")).toBeNull(); }); it("matches folder names stored decomposed, as macOS Finder names them", () => { diff --git a/packages/client-runtime/src/state/filesystem.ts b/packages/client-runtime/src/state/filesystem.ts index c5b3072f4b199..5a5a907fd1829 100644 --- a/packages/client-runtime/src/state/filesystem.ts +++ b/packages/client-runtime/src/state/filesystem.ts @@ -135,7 +135,14 @@ export function getFilesystemBrowseTabCompletion( visibleEntries: ReadonlyArray, filterQuery: string, ): { readonly name: string; readonly isComplete: boolean } | null { - const [first, ...rest] = visibleEntries; + const lowerQuery = filterQuery.toLowerCase(); + const lowerNormalizedQuery = filterQuery.normalize("NFC").toLowerCase(); + const prefixEntries = visibleEntries.filter( + (entry) => + entry.name.toLowerCase().startsWith(lowerQuery) || + entry.name.normalize("NFC").toLowerCase().startsWith(lowerNormalizedQuery), + ); + const [first, ...rest] = prefixEntries; if (first === undefined) return null; if (rest.length === 0) return { name: first.name, isComplete: true }; let prefix = Array.from(first.name); @@ -151,8 +158,8 @@ export function getFilesystemBrowseTabCompletion( } const name = prefix.join(""); const lowerName = name.toLowerCase(); - return lowerName.length > filterQuery.toLowerCase().length && - visibleEntries.every((entry) => entry.name.toLowerCase().startsWith(lowerName)) + return lowerName.length > lowerQuery.length && + prefixEntries.every((entry) => entry.name.toLowerCase().startsWith(lowerName)) ? { name, isComplete: false } : null; }