@@ -168,8 +168,6 @@ export interface CommandPaletteItem {
168168 readonly timestamp ?: string ;
169169 /** Thread rows rank by this, with use history, instead of by `searchTerms`. */
170170 readonly threadSearch ?: ThreadSearchSubject ;
171- /** Title ranges the current query matched, for highlighting. */
172- readonly titleRanges ?: ReadonlyArray < SearchRange > ;
173171 /** Shown in place of the description when the match is not in the title. */
174172 readonly matchHint ?: SearchMatchHint ;
175173 readonly icon : ReactNode ;
@@ -508,13 +506,29 @@ export function filterCommandPaletteGroups(input: {
508506 activeGroups : ReadonlyArray < CommandPaletteGroup > ;
509507 query : string ;
510508 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+ } ;
511514 projectSearchItems : ReadonlyArray < CommandPaletteActionItem > ;
512515 settingsSearchItems ?: ReadonlyArray < CommandPaletteActionItem > ;
513516 threadSearchItems : ReadonlyArray < CommandPaletteActionItem > ;
514517 /** Threads whose messages match, best first; threads already listed are skipped. */
515518 threadMessageItems ?: ReadonlyArray < CommandPaletteActionItem > ;
516519 now ?: number ;
517520} ) : 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+
518532 const isActionsFilter = input . query . startsWith ( ">" ) ;
519533 const searchQuery = isActionsFilter ? input . query . slice ( 1 ) : input . query ;
520534 const normalizedQuery = foldSearchQuery ( searchQuery ) ;
@@ -538,6 +552,13 @@ export function filterCommandPaletteGroups(input: {
538552 // On equal match classes, groups keep this order: threads, what people search
539553 // for most, right after commands.
540554 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+ }
541562 if ( input . threadSearchItems . length > 0 ) {
542563 searchableGroups . push ( {
543564 value : "threads-search" ,
@@ -572,7 +593,7 @@ export function filterCommandPaletteGroups(input: {
572593 const limit =
573594 group . value === "threads-search"
574595 ? PALETTE_THREAD_LIMIT
575- : searchesEverything && threadsMatch
596+ : group . value === "nested-search" || ( searchesEverything && threadsMatch )
576597 ? PALETTE_SECONDARY_LIMIT
577598 : ranked . length ;
578599 // Hints are built only for the rows shown.
@@ -583,7 +604,7 @@ export function filterCommandPaletteGroups(input: {
583604 )
584605 . slice ( 0 , limit )
585606 . map ( ( { item, match } ) => {
586- if ( match . ranges . length > 0 ) return { ... item , titleRanges : match . ranges } ;
607+ if ( match . ranges . length > 0 ) return item ;
587608 // Built only for the rows shown.
588609 const matchHint = match . explain ?.( ) ;
589610 return matchHint ? { ...item , matchHint } : item ;
@@ -600,6 +621,35 @@ export function filterCommandPaletteGroups(input: {
600621 : [ ...groups , { value : "threads-messages" , label : "In messages" , items : messageItems } ] ;
601622}
602623
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+
603653export function buildBrowseGroups ( input : {
604654 browseEntries : ReadonlyArray < FilesystemBrowseEntry > ;
605655 browseQuery : string ;
0 commit comments