Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launchpad Search: Searches only when nothing is found #3770

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed

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

### Fixed

Expand Down
1 change: 1 addition & 0 deletions src/commands/quickCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface QuickPickStep<T extends QuickPickItem = QuickPickItem> {
onDidActivate?(quickpick: QuickPick<DirectiveQuickPickItem | T>): void;

onDidAccept?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
onDidChangeActive?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
onDidChangeValue?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
onDidChangeSelection?(quickpick: QuickPick<DirectiveQuickPickItem | T>, selection: readonly T[]): void;
onDidClickButton?(
Expand Down
5 changes: 5 additions & 0 deletions src/commands/quickWizard.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ export abstract class QuickWizardCommandBase extends Command {
firstActiveChange = false;
}

if (step.onDidChangeActive != null) {
const cancel = step.onDidChangeActive(quickpick);
if (cancel) return;
}

if (rootStep.command != null || quickpick.activeItems.length === 0) return;

const command = quickpick.activeItems[0];
Expand Down
38 changes: 21 additions & 17 deletions src/plus/launchpad/launchpad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,22 +518,6 @@ export class LaunchpadCommand extends QuickCommand<State> {
};
}

const combineQuickpickItemsWithSearchResults = <T extends { item: { id: string } } | object>(
arr: readonly T[],
items: T[],
) => {
const ids: Set<string> = new Set(
arr.map(i => 'item' in i && i.item?.id).filter(id => typeof id === 'string'),
);
const result = [...arr];
for (const item of items) {
if ('item' in item && item.item?.id && !ids.has(item.item.id)) {
result.push(item);
}
}
return result;
};

const updateItems = async (
quickpick: QuickPick<LaunchpadItemQuickPickItem | DirectiveQuickPickItem | ConnectMoreIntegrationsItem>,
) => {
Expand All @@ -552,7 +536,7 @@ export class LaunchpadCommand extends QuickCommand<State> {
}
const { items, placeholder } = getItemsAndPlaceholder(Boolean(search));
quickpick.placeholder = placeholder;
quickpick.items = search ? combineQuickpickItemsWithSearchResults(quickpick.items, items) : items;
quickpick.items = items;
});
} finally {
quickpick.busy = false;
Expand All @@ -575,6 +559,17 @@ export class LaunchpadCommand extends QuickCommand<State> {
LaunchpadSettingsQuickInputButton,
RefreshQuickInputButton,
],

onDidChangeActive: quickpick => {
const hasActiveLaunchpadItems = quickpick.activeItems.find(i => 'item' in i);
if (hasActiveLaunchpadItems) {
this.updateItemsDebouncer.cancel();
return true;
}

return false;
},

onDidChangeValue: async quickpick => {
const { value } = quickpick;
const hideGroups = Boolean(value?.length);
Expand Down Expand Up @@ -630,6 +625,15 @@ export class LaunchpadCommand extends QuickCommand<State> {
}
}

// Here we cannot check for active items, because they are not yet updated after the last search value.
// So, we immediately init updating process, without a condition.
// But it's delayed by a debouncer.
//
// Right after the `onDidChangeValue` it goes to `onDidChangeActive`, where active items are already updated.
// It happens very soon much after that the delay of the debouncer.
//
// If it occurs that the quickpic has an active item, it cancells the update operation,
// it happens before the update procedure starts executing.
await updateItems(quickpick);
return true;
},
Expand Down
Loading