Skip to content

Commit bc466d0

Browse files
chivorotkivsergeibbb
authored andcommitted
Searches only when nothing is found
(#3763, #3770)
1 parent 1605896 commit bc466d0

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1717
### Changed
1818

1919
- Changes the _Search & Compare_ view to be separate (detached) from the new grouped _GitLens_ view
20+
- API search in the _Launchpad_ is activated only when nothing is found locally
2021

2122
### Fixed
2223

src/plus/launchpad/launchpad.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -518,22 +518,6 @@ export class LaunchpadCommand extends QuickCommand<State> {
518518
};
519519
}
520520

521-
const combineQuickpickItemsWithSearchResults = <T extends { item: { id: string } } | object>(
522-
arr: readonly T[],
523-
items: T[],
524-
) => {
525-
const ids: Set<string> = new Set(
526-
arr.map(i => 'item' in i && i.item?.id).filter(id => typeof id === 'string'),
527-
);
528-
const result = [...arr];
529-
for (const item of items) {
530-
if ('item' in item && item.item?.id && !ids.has(item.item.id)) {
531-
result.push(item);
532-
}
533-
}
534-
return result;
535-
};
536-
537521
const updateItems = async (
538522
quickpick: QuickPick<LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem>,
539523
) => {
@@ -552,7 +536,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
552536
}
553537
const { items, placeholder } = getItemsAndPlaceholder(Boolean(search));
554538
quickpick.placeholder = placeholder;
555-
quickpick.items = search ? combineQuickpickItemsWithSearchResults(quickpick.items, items) : items;
539+
quickpick.items = items;
556540
});
557541
} finally {
558542
quickpick.busy = false;
@@ -630,6 +614,15 @@ export class LaunchpadCommand extends QuickCommand<State> {
630614
}
631615
}
632616

617+
// wait a little bit because the active quickpick is updated with some delay
618+
await new Promise(resolve => setTimeout(resolve, 100));
619+
const hasActiveLaunchpadItems = quickpick.activeItems.find(i => 'item' in i);
620+
if (hasActiveLaunchpadItems) {
621+
// We have an active item, so we can exit now without sending any requests to API
622+
this.updateItemsDebouncer.cancel();
623+
return true;
624+
}
625+
633626
await updateItems(quickpick);
634627
return true;
635628
},

0 commit comments

Comments
 (0)