@@ -422,6 +422,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
422422 i : LaunchpadItem ,
423423 ui : LaunchpadGroup ,
424424 topItem : LaunchpadItem | undefined ,
425+ alwaysShow : boolean | undefined ,
425426 ) : LaunchpadItemQuickPickItem => {
426427 const buttons = [ ] ;
427428
@@ -452,6 +453,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
452453 i . actionableCategory === 'other' ? '' : `${ actionGroupMap . get ( i . actionableCategory ) ! [ 0 ] } \u2022 `
453454 } ${ fromNow ( i . updatedDate ) } by @${ i . author ! . username } `,
454455
456+ alwaysShow : alwaysShow ,
455457 buttons : buttons ,
456458 iconPath : i . author ?. avatarUrl != null ? Uri . parse ( i . author . avatarUrl ) : undefined ,
457459 item : i ,
@@ -460,7 +462,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
460462 } ;
461463 } ;
462464
463- const getItems = ( result : LaunchpadCategorizedResult , treatAllGroupAsExpanded ?: boolean ) => {
465+ const getItems = ( result : LaunchpadCategorizedResult , isSearching ?: boolean ) => {
464466 const items : ( LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem ) [ ] = [ ] ;
465467
466468 if ( result . items ?. length ) {
@@ -475,18 +477,21 @@ export class LaunchpadCommand extends QuickCommand<State> {
475477 for ( const [ ui , groupItems ] of uiGroups ) {
476478 if ( ! groupItems . length ) continue ;
477479
478- items . push ( ...buildGroupHeading ( ui , groupItems . length ) ) ;
479-
480- if ( ! treatAllGroupAsExpanded && context . collapsed . get ( ui ) ) continue ;
480+ if ( ! isSearching ) {
481+ items . push ( ...buildGroupHeading ( ui , groupItems . length ) ) ;
482+ if ( context . collapsed . get ( ui ) ) {
483+ continue ;
484+ }
485+ }
481486
482- items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem ) ) ) ;
487+ items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem , isSearching ) ) ) ;
483488 }
484489 }
485490
486491 return items ;
487492 } ;
488493
489- function getItemsAndPlaceholder ( treatAllGroupAsExpanded ?: boolean ) {
494+ function getItemsAndPlaceholder ( isSearching ?: boolean ) {
490495 if ( context . result . error != null ) {
491496 return {
492497 placeholder : `Unable to load items (${
@@ -509,7 +514,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
509514
510515 return {
511516 placeholder : 'Choose an item to focus on' ,
512- items : getItems ( context . result , treatAllGroupAsExpanded ) ,
517+ items : getItems ( context . result , isSearching ) ,
513518 } ;
514519 }
515520
@@ -539,8 +544,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
539544 } ;
540545
541546 const { items, placeholder } = getItemsAndPlaceholder ( ) ;
542-
543- let groupsHidden = false ;
547+ const nonGroupedItems = items . filter ( i => ! isDirectiveQuickPickItem ( i ) ) ;
544548
545549 const step = createPickStep ( {
546550 title : context . title ,
@@ -556,32 +560,27 @@ export class LaunchpadCommand extends QuickCommand<State> {
556560 RefreshQuickInputButton ,
557561 ] ,
558562 onDidChangeValue : async quickpick => {
559- const hideGroups = Boolean ( quickpick . value ?. length ) ;
560-
561- if ( groupsHidden !== hideGroups ) {
562- groupsHidden = hideGroups ;
563- quickpick . items = hideGroups ? items . filter ( i => ! isDirectiveQuickPickItem ( i ) ) : items ;
564- }
565563 const { value } = quickpick ;
566- const activeLaunchpadItems = quickpick . activeItems . filter (
567- ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i && ! i . alwaysShow ,
568- ) ;
564+ const hideGroups = Boolean ( value ?. length ) ;
565+ const consideredItems = hideGroups ? nonGroupedItems : items ;
569566
570567 let updated = false ;
571- for ( const item of quickpick . items ) {
568+ for ( const item of consideredItems ) {
572569 if ( item . alwaysShow ) {
573570 item . alwaysShow = false ;
574571 updated = true ;
575572 }
576- if ( 'item' in item && item . item ?. isSearched ) {
577- updated = true ;
578- }
579- }
580- if ( updated ) {
581- // Force quickpick to update by changing the items object:
582- quickpick . items = [ ...quickpick . items . filter ( i => ! ( 'item' in i && i . item ?. isSearched ) ) ] ;
583573 }
584574
575+ // By doing the following we make sure we operate with the PRs that belong to Launchpad initially.
576+ // Also, when we re-create the array, we make sure that `alwaysShow` updates are applied.
577+ quickpick . items =
578+ updated && quickpick . items === consideredItems ? [ ...consideredItems ] : consideredItems ;
579+
580+ const activeLaunchpadItems = quickpick . activeItems . filter (
581+ ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i ,
582+ ) ;
583+
585584 if ( ! value ?. length || activeLaunchpadItems . length ) {
586585 // Nothing to search or use items that have been found locally
587586 this . updateItemsDebouncer . cancel ( ) ;
@@ -622,13 +621,6 @@ export class LaunchpadCommand extends QuickCommand<State> {
622621 }
623622 // Nothing is found above, so let's perform search in the API:
624623 await updateItems ( quickpick , value ) ;
625- quickpick . items . forEach ( i => {
626- if ( 'item' in i && doesPullRequestSatisfyRepositoryURLIdentity ( i . item , prUrlIdentity ) ) {
627- i . alwaysShow = true ;
628- }
629- } ) ;
630- quickpick . items = quickpick . items . filter ( ( i ) : i is LaunchpadItemQuickPickItem => 'item' in i ) ;
631- groupsHidden = true ;
632624 return true ;
633625 } ,
634626 onDidClickButton : async ( quickpick , button ) => {
@@ -1369,12 +1361,7 @@ async function updateContextItems(
13691361 options ?: { force ?: boolean ; search ?: string } ,
13701362 cancellation ?: CancellationToken ,
13711363) {
1372- const result = await container . launchpad . getCategorizedItems ( options , cancellation ) ;
1373- if ( options ?. search != null ) {
1374- context . result = container . launchpad . mergeSearchedCategorizedItems ( context . result , result ) ;
1375- } else {
1376- context . result = result ;
1377- }
1364+ context . result = await container . launchpad . getCategorizedItems ( options , cancellation ) ;
13781365 if ( container . telemetry . enabled ) {
13791366 updateTelemetryContext ( context ) ;
13801367 }
0 commit comments