@@ -419,6 +419,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
419
419
i : LaunchpadItem ,
420
420
ui : LaunchpadGroup ,
421
421
topItem : LaunchpadItem | undefined ,
422
+ alwaysShow : boolean | undefined ,
422
423
) : LaunchpadItemQuickPickItem => {
423
424
const buttons = [ ] ;
424
425
@@ -449,6 +450,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
449
450
i . actionableCategory === 'other' ? '' : `${ actionGroupMap . get ( i . actionableCategory ) ! [ 0 ] } \u2022 `
450
451
} ${ fromNow ( i . updatedDate ) } by @${ i . author ! . username } `,
451
452
453
+ alwaysShow : alwaysShow ,
452
454
buttons : buttons ,
453
455
iconPath : i . author ?. avatarUrl != null ? Uri . parse ( i . author . avatarUrl ) : undefined ,
454
456
item : i ,
@@ -457,7 +459,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
457
459
} ;
458
460
} ;
459
461
460
- const getItems = ( result : LaunchpadCategorizedResult ) => {
462
+ const getItems = ( result : LaunchpadCategorizedResult , isSearching ?: boolean ) => {
461
463
const items : ( LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem ) [ ] = [ ] ;
462
464
463
465
if ( result . items ?. length ) {
@@ -472,18 +474,21 @@ export class LaunchpadCommand extends QuickCommand<State> {
472
474
for ( const [ ui , groupItems ] of uiGroups ) {
473
475
if ( ! groupItems . length ) continue ;
474
476
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
+ }
478
483
479
- items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem ) ) ) ;
484
+ items . push ( ...groupItems . map ( i => buildLaunchpadQuickPickItem ( i , ui , topItem , isSearching ) ) ) ;
480
485
}
481
486
}
482
487
483
488
return items ;
484
489
} ;
485
490
486
- function getItemsAndPlaceholder ( ) {
491
+ function getItemsAndPlaceholder ( isSearching ?: boolean ) {
487
492
if ( context . result . error != null ) {
488
493
return {
489
494
placeholder : `Unable to load items (${
@@ -506,17 +511,18 @@ export class LaunchpadCommand extends QuickCommand<State> {
506
511
507
512
return {
508
513
placeholder : 'Choose an item to focus on' ,
509
- items : getItems ( context . result ) ,
514
+ items : getItems ( context . result , isSearching ) ,
510
515
} ;
511
516
}
512
517
513
518
const updateItems = async (
514
519
quickpick : QuickPick < LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem > ,
515
520
) => {
521
+ const search = quickpick . value ;
516
522
quickpick . busy = true ;
517
523
518
524
try {
519
- await updateContextItems ( this . container , context , { force : true } ) ;
525
+ await updateContextItems ( this . container , context , { force : true , search : search } ) ;
520
526
521
527
const { items, placeholder } = getItemsAndPlaceholder ( ) ;
522
528
quickpick . placeholder = placeholder ;
@@ -527,8 +533,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
527
533
} ;
528
534
529
535
const { items, placeholder } = getItemsAndPlaceholder ( ) ;
530
-
531
- let groupsHidden = false ;
536
+ const nonGroupedItems = items . filter ( i => ! isDirectiveQuickPickItem ( i ) ) ;
532
537
533
538
const step = createPickStep ( {
534
539
title : context . title ,
@@ -543,29 +548,27 @@ export class LaunchpadCommand extends QuickCommand<State> {
543
548
LaunchpadSettingsQuickInputButton ,
544
549
RefreshQuickInputButton ,
545
550
] ,
546
- onDidChangeValue : quickpick => {
551
+ onDidChangeValue : async quickpick => {
547
552
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 ;
557
555
558
556
let updated = false ;
559
- for ( const item of quickpick . items ) {
557
+ for ( const item of consideredItems ) {
560
558
if ( item . alwaysShow ) {
561
559
item . alwaysShow = false ;
562
560
updated = true ;
563
561
}
564
562
}
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
+ ) ;
569
572
570
573
if ( ! value ?. length || activeLaunchpadItems . length ) {
571
574
// Nothing to search
@@ -588,7 +591,12 @@ export class LaunchpadCommand extends QuickCommand<State> {
588
591
item . alwaysShow = true ;
589
592
// Force quickpick to update by changing the items object:
590
593
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 ;
591
597
}
598
+ // Nothing is found above, so let's perform search in the API:
599
+ await updateItems ( quickpick ) ;
592
600
}
593
601
}
594
602
@@ -1377,7 +1385,11 @@ function getIntegrationTitle(integrationId: string): string {
1377
1385
}
1378
1386
}
1379
1387
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
+ ) {
1381
1393
context . result = await container . launchpad . getCategorizedItems ( options ) ;
1382
1394
if ( container . telemetry . enabled ) {
1383
1395
updateTelemetryContext ( context ) ;
0 commit comments