@@ -419,6 +419,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
419419 i : LaunchpadItem ,
420420 ui : LaunchpadGroup ,
421421 topItem : LaunchpadItem | undefined ,
422+ alwaysShow : boolean | undefined ,
422423 ) : LaunchpadItemQuickPickItem => {
423424 const buttons = [ ] ;
424425
@@ -449,6 +450,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
449450 i . actionableCategory === 'other' ? '' : `${ actionGroupMap . get ( i . actionableCategory ) ! [ 0 ] } \u2022 `
450451 } ${ fromNow ( i . updatedDate ) } by @${ i . author ! . username } `,
451452
453+ alwaysShow : alwaysShow ,
452454 buttons : buttons ,
453455 iconPath : i . author ?. avatarUrl != null ? Uri . parse ( i . author . avatarUrl ) : undefined ,
454456 item : i ,
@@ -457,7 +459,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
457459 } ;
458460 } ;
459461
460- const getItems = ( result : LaunchpadCategorizedResult ) => {
462+ const getItems = ( result : LaunchpadCategorizedResult , isSearching ?: boolean ) => {
461463 const items : ( LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem ) [ ] = [ ] ;
462464
463465 if ( result . items ?. length ) {
@@ -472,18 +474,21 @@ export class LaunchpadCommand extends QuickCommand<State> {
472474 for ( const [ ui , groupItems ] of uiGroups ) {
473475 if ( ! groupItems . length ) continue ;
474476
475- items . push ( ...buildGroupHeading ( ui , groupItems . length ) ) ;
476-
477- if ( context . collapsed . get ( ui ) ) continue ;
477+ if ( ! isSearching ) {
478+ items . push ( ...buildGroupHeading ( ui , groupItems . length ) ) ;
479+ if ( context . collapsed . get ( ui ) ) {
480+ continue ;
481+ }
482+ }
478483
479- items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem ) ) ) ;
484+ items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem , isSearching ) ) ) ;
480485 }
481486 }
482487
483488 return items ;
484489 } ;
485490
486- function getItemsAndPlaceholder ( ) {
491+ function getItemsAndPlaceholder ( isSearching ?: boolean ) {
487492 if ( context . result . error != null ) {
488493 return {
489494 placeholder : `Unable to load items (${
@@ -506,17 +511,18 @@ export class LaunchpadCommand extends QuickCommand<State> {
506511
507512 return {
508513 placeholder : 'Choose an item to focus on' ,
509- items : getItems ( context . result ) ,
514+ items : getItems ( context . result , isSearching ) ,
510515 } ;
511516 }
512517
513518 const updateItems = async (
514519 quickpick : QuickPick < LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem > ,
515520 ) => {
521+ const search = quickpick . value ;
516522 quickpick . busy = true ;
517523
518524 try {
519- await updateContextItems ( this . container , context , { force : true } ) ;
525+ await updateContextItems ( this . container , context , { force : true , search : search } ) ;
520526
521527 const { items, placeholder } = getItemsAndPlaceholder ( ) ;
522528 quickpick . placeholder = placeholder ;
@@ -527,8 +533,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
527533 } ;
528534
529535 const { items, placeholder } = getItemsAndPlaceholder ( ) ;
530-
531- let groupsHidden = false ;
536+ const nonGroupedItems = items . filter ( i => ! isDirectiveQuickPickItem ( i ) ) ;
532537
533538 const step = createPickStep ( {
534539 title : context . title ,
@@ -543,29 +548,27 @@ export class LaunchpadCommand extends QuickCommand<State> {
543548 LaunchpadSettingsQuickInputButton ,
544549 RefreshQuickInputButton ,
545550 ] ,
546- onDidChangeValue : quickpick => {
551+ onDidChangeValue : async quickpick => {
547552 const { value } = quickpick ;
548- const hideGroups = Boolean ( quickpick . value ?. length ) ;
549-
550- if ( groupsHidden !== hideGroups ) {
551- groupsHidden = hideGroups ;
552- quickpick . items = hideGroups ? items . filter ( i => ! isDirectiveQuickPickItem ( i ) ) : items ;
553- }
554- const activeLaunchpadItems = quickpick . activeItems . filter (
555- ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i && ! i . alwaysShow ,
556- ) ;
553+ const hideGroups = Boolean ( value ?. length ) ;
554+ const consideredItems = hideGroups ? nonGroupedItems : items ;
557555
558556 let updated = false ;
559- for ( const item of quickpick . items ) {
557+ for ( const item of consideredItems ) {
560558 if ( item . alwaysShow ) {
561559 item . alwaysShow = false ;
562560 updated = true ;
563561 }
564562 }
565- if ( updated ) {
566- // Force quickpick to update by changing the items object:
567- quickpick . items = [ ...quickpick . items ] ;
568- }
563+
564+ // By doing the following we make sure we operate with the PRs that belong to Launchpad initially.
565+ // Also, when we re-create the array, we make sure that `alwaysShow` updates are applied.
566+ quickpick . items =
567+ updated && quickpick . items === consideredItems ? [ ...consideredItems ] : consideredItems ;
568+
569+ const activeLaunchpadItems = quickpick . activeItems . filter (
570+ ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i ,
571+ ) ;
569572
570573 if ( ! value ?. length || activeLaunchpadItems . length ) {
571574 // Nothing to search
@@ -588,7 +591,12 @@ export class LaunchpadCommand extends QuickCommand<State> {
588591 item . alwaysShow = true ;
589592 // Force quickpick to update by changing the items object:
590593 quickpick . items = [ ...quickpick . items ] ;
594+ // We have found an item that matches to the URL.
595+ // Now it will be displayed as the found item and we exit this function now without sending any requests to API:
596+ return true ;
591597 }
598+ // Nothing is found above, so let's perform search in the API:
599+ await updateItems ( quickpick ) ;
592600 }
593601 }
594602
@@ -1377,7 +1385,11 @@ function getIntegrationTitle(integrationId: string): string {
13771385 }
13781386}
13791387
1380- async function updateContextItems ( container : Container , context : Context , options ?: { force ?: boolean } ) {
1388+ async function updateContextItems (
1389+ container : Container ,
1390+ context : Context ,
1391+ options ?: { force ?: boolean ; search ?: string } ,
1392+ ) {
13811393 context . result = await container . launchpad . getCategorizedItems ( options ) ;
13821394 if ( container . telemetry . enabled ) {
13831395 updateTelemetryContext ( context ) ;
0 commit comments