Skip to content

Commit

Permalink
Fix bug in pickComplex for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Dec 17, 2020
1 parent 4a7b456 commit b0155c5
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/ui-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function formatItem(item: FileSystemConfig | Connection | SSHFileSystem |
}
}

type QuickPickItemWithValue = vscode.QuickPickItem & { value?: any };
type QuickPickItemWithItem = vscode.QuickPickItem & { item: any };

export interface PickComplexOptions {
/** If true and there is only one or none item is available, immediately resolve with it/undefined */
Expand All @@ -82,7 +82,7 @@ export async function pickComplex(manager: Manager, options: PickComplexOptions)
Promise<FileSystemConfig | Connection | SSHPseudoTerminal | undefined> {
return new Promise((resolve) => {
const { promptConnections, promptConfigs, promptTerminals, immediateReturn, nameFilter } = options;
const items: QuickPickItemWithValue[] = [];
const items: QuickPickItemWithItem[] = [];
const toSelect: string[] = [];
if (promptConnections) {
let cons = manager.connectionManager.getActiveConnections();
Expand All @@ -106,13 +106,12 @@ export async function pickComplex(manager: Manager, options: PickComplexOptions)
items.push(...terminals.map(config => formatItem(config, true)));
toSelect.push('terminal');
}
if (immediateReturn && items.length <= 1) return resolve(items[0]?.value);
const quickPick = vscode.window.createQuickPick<QuickPickItemWithValue>();
if (immediateReturn && items.length <= 1) return resolve(items[0]?.item);
const quickPick = vscode.window.createQuickPick<QuickPickItemWithItem>();
quickPick.items = items;
quickPick.title = 'Select ' + toSelect.join(' / ');
quickPick.onDidAccept(() => {
const value = quickPick.activeItems[0]?.value;
if (!value) return;
const value = quickPick.activeItems[0]?.item;
quickPick.hide();
resolve(value);
});
Expand Down

0 comments on commit b0155c5

Please sign in to comment.