Skip to content

Commit 9b17351

Browse files
committed
Improves delayed detection of active items: uses onDidChangeActive
instead of a timout delay (#3763, #3770)
1 parent 162f26a commit 9b17351

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/commands/quickCommand.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface QuickPickStep<T extends QuickPickItem = QuickPickItem> {
7171
onDidActivate?(quickpick: QuickPick<DirectiveQuickPickItem | T>): void;
7272

7373
onDidAccept?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
74+
onDidChangeActive?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
7475
onDidChangeValue?(quickpick: QuickPick<DirectiveQuickPickItem | T>): boolean | Promise<boolean>;
7576
onDidChangeSelection?(quickpick: QuickPick<DirectiveQuickPickItem | T>, selection: readonly T[]): void;
7677
onDidClickButton?(

src/commands/quickWizard.base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ export abstract class QuickWizardCommandBase extends Command {
621621
firstActiveChange = false;
622622
}
623623

624+
if (step.onDidChangeActive != null) {
625+
const cancel = step.onDidChangeActive(quickpick);
626+
if (cancel) return;
627+
}
628+
624629
if (rootStep.command != null || quickpick.activeItems.length === 0) return;
625630

626631
const command = quickpick.activeItems[0];

src/plus/launchpad/launchpad.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ export class LaunchpadCommand extends QuickCommand<State> {
559559
LaunchpadSettingsQuickInputButton,
560560
RefreshQuickInputButton,
561561
],
562+
563+
onDidChangeActive: quickpick => {
564+
const hasActiveLaunchpadItems = quickpick.activeItems.find(i => 'item' in i);
565+
if (hasActiveLaunchpadItems) {
566+
this.updateItemsDebouncer.cancel();
567+
return true;
568+
}
569+
570+
return false;
571+
},
572+
562573
onDidChangeValue: async quickpick => {
563574
const { value } = quickpick;
564575
const hideGroups = Boolean(value?.length);
@@ -614,15 +625,15 @@ export class LaunchpadCommand extends QuickCommand<State> {
614625
}
615626
}
616627

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-
628+
// Here we cannot check for active items, because they are not yet updated after the last search value.
629+
// So, we immediately init updating process, without a condition.
630+
// But it's delayed by a debouncer.
631+
//
632+
// Right after the `onDidChangeValue` it goes to `onDidChangeActive`, where active items are already updated.
633+
// It happens very soon much after that the delay of the debouncer.
634+
//
635+
// If it occurs that the quickpic has an active item, it cancells the update operation,
636+
// it happens before the update procedure starts executing.
626637
await updateItems(quickpick);
627638
return true;
628639
},

0 commit comments

Comments
 (0)