Skip to content

Commit 1cd66cb

Browse files
committed
Ensure picker returns array only if multi-select is enabled (microsoft#20772)
Fixes microsoft#20768
1 parent 7c31a5e commit 1cd66cb

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/client/common/vscodeApis/windowApis.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ export async function showQuickPickWithBack<T extends QuickPickItem>(
112112
}),
113113
quickPick.onDidAccept(() => {
114114
if (!deferred.completed) {
115-
deferred.resolve(quickPick.selectedItems.map((item) => item));
115+
if (quickPick.canSelectMany) {
116+
deferred.resolve(quickPick.selectedItems.map((item) => item));
117+
} else {
118+
deferred.resolve(quickPick.selectedItems[0]);
119+
}
120+
116121
quickPick.hide();
117122
}
118123
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { assert } from 'chai';
5+
import * as sinon from 'sinon';
6+
import { CancellationTokenSource } from 'vscode';
7+
import * as windowApis from '../../../../client/common/vscodeApis/windowApis';
8+
import { pickPythonVersion } from '../../../../client/pythonEnvironments/creation/provider/condaUtils';
9+
10+
suite('Conda Utils test', () => {
11+
let showQuickPickWithBackStub: sinon.SinonStub;
12+
13+
setup(() => {
14+
showQuickPickWithBackStub = sinon.stub(windowApis, 'showQuickPickWithBack');
15+
});
16+
17+
teardown(() => {
18+
sinon.restore();
19+
});
20+
21+
test('No version selected or user pressed escape', async () => {
22+
showQuickPickWithBackStub.resolves(undefined);
23+
24+
const actual = await pickPythonVersion();
25+
assert.isUndefined(actual);
26+
});
27+
28+
test('User selected a version', async () => {
29+
showQuickPickWithBackStub.resolves({ label: 'Python', description: '3.10' });
30+
31+
const actual = await pickPythonVersion();
32+
assert.equal(actual, '3.10');
33+
});
34+
35+
test('With cancellation', async () => {
36+
const source = new CancellationTokenSource();
37+
38+
showQuickPickWithBackStub.callsFake(() => {
39+
source.cancel();
40+
});
41+
42+
const actual = await pickPythonVersion(source.token);
43+
assert.isUndefined(actual);
44+
});
45+
});

0 commit comments

Comments
 (0)