@devries-cameron20 / t3code Mirror · read-only / commits / e9d61252f6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 18:15 UTC

feat(web): command palette search finds options inside submenus (#24709)

maria committed Oct 25, 2026 at 05:00 UTC e9d61252f6fd8369b80fe8f7e07209cbbb7221d9
5 files changed +118 -16
apps/web/src/components/CommandPalette.logic.test.ts
+51
@@ -3,6 +3,7 @@ import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools
3 import type { Thread } from "../types";
4 import { makeThreadFixture } from "../test-fixtures";
5 import {
6 + buildNestedSearchItems,
7 buildThreadActionItems,
8 buildLinkedThreadActionItems,
9 filterPinnedBrowseEntries,
@@ -168,6 +169,56 @@ describe("buildThreadActionItems", () => {
169 ]);
170 });
171
172 + it("searches submenu options from the root and from a submenu with no match", () => {
173 + const action = (value: string, title: string) => ({
174 + kind: "action" as const,
175 + value,
176 + searchTerms: [title],
177 + title,
178 + icon: null,
179 + run: async () => undefined,
180 + });
181 + const projects = [action("new-thread-in:t3code", "t3code"), action("new-thread-in:web", "web")];
182 + const newThreadIn = {
183 + kind: "submenu" as const,
184 + value: "action:new-thread-in",
185 + searchTerms: ["new thread"],
186 + title: "New thread in...",
187 + icon: null,
188 + addonIcon: null,
189 + groups: [{ value: "projects", label: "Projects", items: projects }],
190 + };
191 + const addProject = action("action:add-project", "Add project");
192 + const rootGroups = [{ value: "actions", label: "Actions", items: [newThreadIn, addProject] }];
193 + const search = (query: string, isInSubmenu: boolean) =>
194 + filterCommandPaletteGroups({
195 + activeGroups: isInSubmenu ? newThreadIn.groups : rootGroups,
196 + query,
197 + isInSubmenu,
198 + allOptions: {
199 + rootGroups,
200 + nestedItems: buildNestedSearchItems([newThreadIn, addProject], query),
201 + },
202 + projectSearchItems: [],
203 + threadSearchItems: [
204 + ...buildThreadActionItems({
205 + threads: [makeThread({ title: "Thread about t3code" })],
206 + projectByKey: new Map(),
207 + icon: null,
208 + runThread: async () => undefined,
209 + }),
210 + ],
211 + }).map((group) => [group.label, group.items.map((item) => item.title)]);
212 +
213 + expect(search("new thread in t3code", false)[0]).toEqual([
214 + "Suggestions",
215 + ["New thread in t3code"],
216 + ]);
217 + expect(search("new thread", false).map(([label]) => label)).not.toContain("Suggestions");
218 + expect(search("t3", true)).toEqual([["Projects", ["t3code"]]]);
219 + expect(search("add project", true)).toEqual([["Actions", ["Add project"]]]);
220 + });
221 +
222 it("lists message matches last, once, without moving the title matches above them", () => {
223 const threads = [
224 makeThread({ id: ThreadId.make("title"), title: "Disable Convex schema validation" }),
apps/web/src/components/CommandPalette.logic.ts
+54 -4
@@ -168,8 +168,6 @@ export interface CommandPaletteItem {
168 readonly timestamp?: string;
169 /** Thread rows rank by this, with use history, instead of by `searchTerms`. */
170 readonly threadSearch?: ThreadSearchSubject;
171 - /** Title ranges the current query matched, for highlighting. */
172 - readonly titleRanges?: ReadonlyArray<SearchRange>;
171 /** Shown in place of the description when the match is not in the title. */
172 readonly matchHint?: SearchMatchHint;
173 readonly icon: ReactNode;
@@ -508,6 +506,11 @@ export function filterCommandPaletteGroups(input: {
506 activeGroups: ReadonlyArray<CommandPaletteGroup>;
507 query: string;
508 isInSubmenu: boolean;
509 + /** Submenu options join the root search, and a submenu with no match falls back to it. */
510 + allOptions?: {
511 + readonly rootGroups: ReadonlyArray<CommandPaletteGroup>;
512 + readonly nestedItems: ReadonlyArray<CommandPaletteActionItem>;
513 + };
514 projectSearchItems: ReadonlyArray<CommandPaletteActionItem>;
515 settingsSearchItems?: ReadonlyArray<CommandPaletteActionItem>;
516 threadSearchItems: ReadonlyArray<CommandPaletteActionItem>;
@@ -515,6 +518,17 @@ export function filterCommandPaletteGroups(input: {
518 threadMessageItems?: ReadonlyArray<CommandPaletteActionItem>;
519 now?: number;
520 }): CommandPaletteGroup[] {
521 + if (input.allOptions && input.isInSubmenu) {
522 + const { allOptions, ...submenuInput } = input;
523 + const scoped = filterCommandPaletteGroups(submenuInput);
524 + if (scoped.length > 0 || input.query.trim().length === 0) return scoped;
525 + return filterCommandPaletteGroups({
526 + ...input,
527 + activeGroups: allOptions.rootGroups,
528 + isInSubmenu: false,
529 + });
530 + }
531 +
532 const isActionsFilter = input.query.startsWith(">");
533 const searchQuery = isActionsFilter ? input.query.slice(1) : input.query;
534 const normalizedQuery = foldSearchQuery(searchQuery);
@@ -538,6 +552,13 @@ export function filterCommandPaletteGroups(input: {
552 // On equal match classes, groups keep this order: threads, what people search
553 // for most, right after commands.
554 if (searchesEverything) {
555 + if (input.allOptions && input.allOptions.nestedItems.length > 0) {
556 + searchableGroups.push({
557 + value: "nested-search",
558 + label: "Suggestions",
559 + items: input.allOptions.nestedItems,
560 + });
561 + }
562 if (input.threadSearchItems.length > 0) {
563 searchableGroups.push({
564 value: "threads-search",
@@ -572,7 +593,7 @@ export function filterCommandPaletteGroups(input: {
593 const limit =
594 group.value === "threads-search"
595 ? PALETTE_THREAD_LIMIT
575 - : searchesEverything && threadsMatch
596 + : group.value === "nested-search" || (searchesEverything && threadsMatch)
597 ? PALETTE_SECONDARY_LIMIT
598 : ranked.length;
599 // Hints are built only for the rows shown.
@@ -583,7 +604,7 @@ export function filterCommandPaletteGroups(input: {
604 )
605 .slice(0, limit)
606 .map(({ item, match }) => {
586 - if (match.ranges.length > 0) return { ...item, titleRanges: match.ranges };
607 + if (match.ranges.length > 0) return item;
608 // Built only for the rows shown.
609 const matchHint = match.explain?.();
610 return matchHint ? { ...item, matchHint } : item;
@@ -600,6 +621,35 @@ export function filterCommandPaletteGroups(input: {
621 : [...groups, { value: "threads-messages", label: "In messages", items: messageItems }];
622 }
623
624 +/** Every option inside a submenu as one row, e.g. "New thread in t3code" or "Change theme: Dracula". */
625 +export function buildNestedSearchItems(
626 + items: ReadonlyArray<CommandPaletteActionItem | CommandPaletteSubmenuItem>,
627 + query: string,
628 +): CommandPaletteActionItem[] {
629 + const nameOf = (item: CommandPaletteItem) =>
630 + typeof item.title === "string" ? item.title : item.searchTitle;
631 + const topLevelNames = new Set(items.map(nameOf));
632 + const foldedQuery = foldSearchQuery(query);
633 + return items.flatMap((parent) => {
634 + if (parent.kind !== "submenu" || typeof parent.title !== "string") return [];
635 + const stem = parent.title.replace(/(\.\.\.|…)$/u, "");
636 + // A query that only names the submenu ("new thread in") wants the submenu row itself.
637 + if (foldSearchQuery(stem).startsWith(foldedQuery)) return [];
638 + const prefix = stem === parent.title ? `${stem}: ` : `${stem.trimEnd()} `;
639 + return parent.groups.flatMap((group) =>
640 + group.items.flatMap((child) => {
641 + const name = nameOf(child);
642 + if (child.kind !== "action" || name === undefined) return [];
643 + const title = `${prefix}${name}`;
644 + if (topLevelNames.has(title)) return [];
645 + const { searchTitle: _searchTitle, ...rest } = child;
646 + // Only the combined title: child keywords like "theme" would list every theme.
647 + return [{ ...rest, title, searchTerms: [title] }];
648 + }),
649 + );
650 + });
651 +}
652 +
653 export function buildBrowseGroups(input: {
654 browseEntries: ReadonlyArray<FilesystemBrowseEntry>;
655 browseQuery: string;
apps/web/src/components/CommandPalette.tsx
+9
@@ -167,6 +167,7 @@ import {
167 type CommandPaletteSubmenuItem,
168 type CommandPaletteView,
169 filterCommandPaletteGroups,
170 + buildNestedSearchItems,
171 filterPinnedBrowseEntries,
172 getCommandPaletteInputPlaceholder,
173 getCommandPaletteMode,
@@ -1681,6 +1682,14 @@ function OpenCommandPaletteDialog(props: {
1682 activeGroups,
1683 query: deferredQuery,
1684 isInSubmenu: currentView !== null,
1685 + ...(deferredQuery.trim().length > 0
1686 + ? {
1687 + allOptions: {
1688 + rootGroups,
1689 + nestedItems: buildNestedSearchItems(actionItems, deferredQuery),
1690 + },
1691 + }
1692 + : {}),
1693 projectSearchItems: projectSearchItems,
1694 settingsSearchItems,
1695 threadSearchItems:
apps/web/src/components/CommandPaletteResults.tsx
+3 -11
@@ -22,11 +22,7 @@ import {
22 CommandShortcut,
23 } from "./ui/command";
24 import { getVirtualizedScrollFadeClassName } from "./ui/scroll-area";
25 -import {
26 - HighlightedSearchText,
27 - SearchMatchHintLine,
28 - ThreadSearchMatchExcerpt,
29 -} from "./ThreadSearchMatch";
25 +import { SearchMatchHintLine, ThreadSearchMatchExcerpt } from "./ThreadSearchMatch";
26
27 interface CommandPaletteResultsProps {
28 emptyStateMessage?: string;
@@ -159,16 +155,12 @@ export function CommandPaletteTitleIcon(props: { children: ReactNode }) {
155 function CommandPaletteTitle({
156 item,
157 }: {
162 - item: Pick<CommandPaletteActionItem | CommandPaletteSubmenuItem, "title" | "titleRanges">;
158 + item: Pick<CommandPaletteActionItem | CommandPaletteSubmenuItem, "title">;
159 }) {
160 const { title } = item;
161 return (
162 <span className="truncate" dir={typeof title === "string" ? textDirection(title) : undefined}>
167 - {typeof title === "string" && item.titleRanges ? (
168 - <HighlightedSearchText text={title} ranges={item.titleRanges} />
169 - ) : (
170 - title
171 - )}
163 + {title}
164 </span>
165 );
166 }
apps/web/src/components/ThreadSearchMatch.tsx
+1 -1
@@ -6,7 +6,7 @@ import {
6 } from "@t3tools/shared/paletteSearch";
7
8 /** `text` with each range in semibold foreground. */
9 -export function HighlightedSearchText(props: { text: string; ranges: ReadonlyArray<SearchRange> }) {
9 +function HighlightedSearchText(props: { text: string; ranges: ReadonlyArray<SearchRange> }) {
10 if (props.ranges.length === 0) return props.text;
11 return splitSearchText(props.text, props.ranges).map((part) =>
12 part.highlighted ? (