Skip to content

Commit

Permalink
Revert "widen try in quickpick"
Browse files Browse the repository at this point in the history
This reverts commit 5415a6d.
  • Loading branch information
TylerLeonhardt committed Nov 11, 2021
1 parent eec726d commit 9c2a4b7
Showing 1 changed file with 66 additions and 65 deletions.
131 changes: 66 additions & 65 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,84 +60,85 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
showQuickPick(itemsOrItemsPromise: string[] | Promise<string[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<QuickPickItem | undefined>;
async showQuickPick(itemsOrItemsPromise: Item[] | Promise<Item[]>, enableProposedApi: boolean, options?: QuickPickOptions, token: CancellationToken = CancellationToken.None): Promise<Item | Item[] | undefined> {

// clear state from last invocation
this._onDidSelectItem = undefined;

const itemsPromise = <Promise<Item[]>>Promise.resolve(itemsOrItemsPromise);

const instance = ++this._instances;

try {
const quickPickWidget = proxy.$show(instance, {
title: options?.title,
placeHolder: options?.placeHolder,
matchOnDescription: options?.matchOnDescription,
matchOnDetail: options?.matchOnDetail,
ignoreFocusLost: options?.ignoreFocusOut,
canPickMany: options?.canPickMany,
}, token);

const widgetClosedMarker = {};
const widgetClosedPromise = quickPickWidget.then(() => widgetClosedMarker);

const result = await Promise.race([widgetClosedPromise, itemsPromise]);
if (result === widgetClosedMarker) {
return undefined;
}
const quickPickWidget = proxy.$show(instance, {
title: options?.title,
placeHolder: options?.placeHolder,
matchOnDescription: options?.matchOnDescription,
matchOnDetail: options?.matchOnDetail,
ignoreFocusLost: options?.ignoreFocusOut,
canPickMany: options?.canPickMany,
}, token);

const widgetClosedMarker = {};
const widgetClosedPromise = quickPickWidget.then(() => widgetClosedMarker);

const result = await Promise.race([widgetClosedPromise, itemsPromise]);
if (result === widgetClosedMarker) {
return undefined;
}

const items = await itemsPromise;

const items = await itemsPromise;

const pickItems: TransferQuickPickItemOrSeparator[] = [];
let lastKind: string | { label: string; } | undefined = undefined;
for (let handle = 0; handle < items.length; handle++) {
const item = items[handle];
let label: string;
let description: string | undefined;
let detail: string | undefined;
let picked: boolean | undefined;
let alwaysShow: boolean | undefined;

if (typeof item === 'string') {
// 'string' items have a kind of undefined so
// if the previous item had a kind, that is considered a
// change and would cause the addition of a separator.
if (lastKind) {
pickItems.push({ type: 'separator' });
lastKind = undefined;
}
label = item;
} else {
if (lastKind !== item.kind) {
const label: string | undefined = typeof item.kind === 'string' ? item.kind : item.kind?.label;
pickItems.push({ type: 'separator', label });
lastKind = item.kind;
}
label = item.label;
description = item.description;
detail = item.detail;
picked = item.picked;
alwaysShow = item.alwaysShow;
const pickItems: TransferQuickPickItemOrSeparator[] = [];
let lastKind: string | { label: string; } | undefined = undefined;
for (let handle = 0; handle < items.length; handle++) {
const item = items[handle];
let label: string;
let description: string | undefined;
let detail: string | undefined;
let picked: boolean | undefined;
let alwaysShow: boolean | undefined;

if (typeof item === 'string') {
// 'string' items have a kind of undefined so
// if the previous item had a kind, that is considered a
// change and would cause the addition of a separator.
if (lastKind) {
pickItems.push({ type: 'separator' });
lastKind = undefined;
}
label = item;
} else {
if (lastKind !== item.kind) {
const label: string | undefined = typeof item.kind === 'string' ? item.kind : item.kind?.label;
pickItems.push({ type: 'separator', label });
lastKind = item.kind;
}
pickItems.push({
label,
description,
handle,
detail,
picked,
alwaysShow
});
label = item.label;
description = item.description;
detail = item.detail;
picked = item.picked;
alwaysShow = item.alwaysShow;
}
pickItems.push({
label,
description,
handle,
detail,
picked,
alwaysShow
});
}

// handle selection changes
if (options && typeof options.onDidSelectItem === 'function') {
this._onDidSelectItem = (handle) => {
options.onDidSelectItem!(items[handle]);
};
}
// handle selection changes
if (options && typeof options.onDidSelectItem === 'function') {
this._onDidSelectItem = (handle) => {
options.onDidSelectItem!(items[handle]);
};
}

// show items
proxy.$setItems(instance, pickItems);
// show items
proxy.$setItems(instance, pickItems);

try {
return quickPickWidget.then(handle => {
if (typeof handle === 'number') {
return items[handle];
Expand Down

0 comments on commit 9c2a4b7

Please sign in to comment.