提交 b86a54e7 编写于 作者: J Johannes Rieken

fix #22453

上级 95f4f8d0
......@@ -290,6 +290,17 @@ suite('window namespace tests', () => {
});
});
test('showQuickPick, never resolve promise and cancel - #22453', function () {
const result = window.showQuickPick(new Promise<string[]>(resolve => { }));
const a = result.then(value => {
assert.equal(value, undefined);
});
const b = commands.executeCommand('workbench.action.closeQuickOpen'),
return Promise.all([a, b]);
});
test('editor, selection change kind', () => {
return workspace.openTextDocument(join(workspace.rootPath || '', './far.js')).then(doc => window.showTextDocument(doc)).then(editor => {
......
......@@ -39,53 +39,58 @@ export class ExtHostQuickOpen extends ExtHostQuickOpenShape {
ignoreFocusLost: options && options.ignoreFocusOut
});
const promise = itemsPromise.then(items => {
let pickItems: MyQuickPickItems[] = [];
for (let handle = 0; handle < items.length; handle++) {
let item = items[handle];
let label: string;
let description: string;
let detail: string;
if (typeof item === 'string') {
label = item;
} else {
label = item.label;
description = item.description;
detail = item.detail;
}
pickItems.push({
label,
description,
handle,
detail
});
}
// handle selection changes
if (options && typeof options.onDidSelectItem === 'function') {
this._onDidSelectItem = (handle) => {
options.onDidSelectItem(items[handle]);
};
const promise = TPromise.any(<TPromise<number | Item[]>[]>[quickPickWidget, itemsPromise]).then(values => {
if (values.key === '0') {
return undefined;
}
// show items
this._proxy.$setItems(pickItems);
return itemsPromise.then(items => {
let pickItems: MyQuickPickItems[] = [];
for (let handle = 0; handle < items.length; handle++) {
let item = items[handle];
let label: string;
let description: string;
let detail: string;
if (typeof item === 'string') {
label = item;
} else {
label = item.label;
description = item.description;
detail = item.detail;
}
pickItems.push({
label,
description,
handle,
detail
});
}
return quickPickWidget.then(handle => {
if (typeof handle === 'number') {
return items[handle];
// handle selection changes
if (options && typeof options.onDidSelectItem === 'function') {
this._onDidSelectItem = (handle) => {
options.onDidSelectItem(items[handle]);
};
}
return undefined;
});
}, (err) => {
this._proxy.$setError(err);
return TPromise.wrapError(err);
});
// show items
this._proxy.$setItems(pickItems);
return quickPickWidget.then(handle => {
if (typeof handle === 'number') {
return items[handle];
}
return undefined;
});
}, (err) => {
this._proxy.$setError(err);
return TPromise.wrapError(err);
});
});
return wireCancellationToken(token, promise, true);
}
......
......@@ -318,16 +318,15 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.pickOpenWidget.layout(this.layoutDimensions);
}
// Detect cancellation while pick promise is loading
let cancelTriggered = false;
this.pickOpenWidget.setCallbacks({
onOk: () => { /* ignore, handle later */ },
onCancel: () => { cancelTriggered = true; },
onType: (value: string) => { /* ignore, handle later */ },
});
return new TPromise<IPickOpenEntry | string>((complete, error, progress) => {
// Detect cancellation while pick promise is loading
this.pickOpenWidget.setCallbacks({
onCancel: () => { complete(void 0); },
onOk: () => { /* ignore, handle later */ },
onType: (value: string) => { /* ignore, handle later */ },
});
// hide widget when being cancelled
token.onCancellationRequested(e => {
if (this.currentPickerToken === currentPickerToken) {
......@@ -339,7 +338,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
// Resolve picks
picksPromise.then(picks => {
if (this.currentPickerToken !== currentPickerToken || cancelTriggered) {
if (this.currentPickerToken !== currentPickerToken) {
return complete(void 0); // Return as canceled if another request came after or user canceled
}
......@@ -827,7 +826,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
const entry = this.instantiationService.createInstance(EditorHistoryEntry, input);
const {labelHighlights, descriptionHighlights} = QuickOpenEntry.highlight(entry, searchValue);
const { labelHighlights, descriptionHighlights } = QuickOpenEntry.highlight(entry, searchValue);
entry.setHighlights(labelHighlights, descriptionHighlights);
results.push(entry);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册