mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 06:38:23 +00:00
Accept on with selection, work around all items becoming active (#57850)
This commit is contained in:
parent
f45ac28666
commit
7ff8bda7e8
3 changed files with 70 additions and 12 deletions
|
@ -129,38 +129,85 @@ suite('window namespace tests', function () {
|
|||
quickPick.selectedItems = [quickPick.items[2]];
|
||||
}, 0);
|
||||
});
|
||||
|
||||
test('createQuickPick, continue after first accept', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'active', 'selection', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], [], ['drei']],
|
||||
selectionItems: [['eins'], [], ['drei']],
|
||||
acceptedItems: {
|
||||
active: [['eins'], ['drei']],
|
||||
selection: [['eins'], ['drei']],
|
||||
dispose: [false, true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
await timeout(async () => {
|
||||
quickPick.items = ['drei', 'vier'].map(label => ({ label }));
|
||||
await timeout(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
}, 0);
|
||||
}, 0);
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void) {
|
||||
function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void, record = false) {
|
||||
const quickPick = window.createQuickPick();
|
||||
let eventIndex = -1;
|
||||
quickPick.onDidChangeActive(items => {
|
||||
if (record) {
|
||||
console.log(`active: [${items.map(item => item.label).join(', ')}]`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
assert.equal('active', expected.events.shift());
|
||||
eventIndex++;
|
||||
assert.equal('active', expected.events.shift(), `onDidChangeActive (event ${eventIndex})`);
|
||||
const expectedItems = expected.activeItems.shift();
|
||||
assert.deepEqual(items.map(item => item.label), expectedItems);
|
||||
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedItems);
|
||||
assert.deepEqual(items.map(item => item.label), expectedItems, `onDidChangeActive event items (event ${eventIndex})`);
|
||||
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedItems, `onDidChangeActive active items (event ${eventIndex})`);
|
||||
} catch (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
quickPick.onDidChangeSelection(items => {
|
||||
if (record) {
|
||||
console.log(`selection: [${items.map(item => item.label).join(', ')}]`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
assert.equal('selection', expected.events.shift());
|
||||
eventIndex++;
|
||||
assert.equal('selection', expected.events.shift(), `onDidChangeSelection (event ${eventIndex})`);
|
||||
const expectedItems = expected.selectionItems.shift();
|
||||
assert.deepEqual(items.map(item => item.label), expectedItems);
|
||||
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedItems);
|
||||
assert.deepEqual(items.map(item => item.label), expectedItems, `onDidChangeSelection event items (event ${eventIndex})`);
|
||||
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedItems, `onDidChangeSelection selected items (event ${eventIndex})`);
|
||||
} catch (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
quickPick.onDidAccept(() => {
|
||||
if (record) {
|
||||
console.log('accept');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
assert.equal('accept', expected.events.shift());
|
||||
eventIndex++;
|
||||
assert.equal('accept', expected.events.shift(), `onDidAccept (event ${eventIndex})`);
|
||||
const expectedActive = expected.acceptedItems.active.shift();
|
||||
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedActive);
|
||||
assert.deepEqual(quickPick.activeItems.map(item => item.label), expectedActive, `onDidAccept active items (event ${eventIndex})`);
|
||||
const expectedSelection = expected.acceptedItems.selection.shift();
|
||||
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedSelection);
|
||||
assert.deepEqual(quickPick.selectedItems.map(item => item.label), expectedSelection, `onDidAccept selected items (event ${eventIndex})`);
|
||||
if (expected.acceptedItems.dispose.shift()) {
|
||||
quickPick.dispose();
|
||||
}
|
||||
|
@ -169,6 +216,11 @@ function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void)
|
|||
}
|
||||
});
|
||||
quickPick.onDidHide(() => {
|
||||
if (record) {
|
||||
console.log('hide');
|
||||
done();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
assert.equal('hide', expected.events.shift());
|
||||
done();
|
||||
|
@ -178,4 +230,8 @@ function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void)
|
|||
});
|
||||
|
||||
return quickPick;
|
||||
}
|
||||
|
||||
async function timeout<T>(run: () => Promise<T> | T, ms: number): Promise<T> {
|
||||
return new Promise<T>(resolve => setTimeout(() => resolve(run()), ms));
|
||||
}
|
|
@ -506,7 +506,9 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
|
|||
}
|
||||
this._selectedItems = selectedItems as T[];
|
||||
this.onDidChangeSelectionEmitter.fire(selectedItems as T[]);
|
||||
this.onDidAcceptEmitter.fire();
|
||||
if (selectedItems.length) {
|
||||
this.onDidAcceptEmitter.fire();
|
||||
}
|
||||
}),
|
||||
this.ui.list.onChangedCheckedElements(checkedItems => {
|
||||
if (!this.canSelectMany) {
|
||||
|
|
|
@ -374,8 +374,8 @@ export class QuickInputList {
|
|||
map.set(element.item, index);
|
||||
return map;
|
||||
}, new Map<IQuickPickItem, number>());
|
||||
this.list.splice(0, this.list.length); // Clear focus and selection first, sending the events when the list is empty.
|
||||
this.list.splice(0, this.list.length, this.elements);
|
||||
this.list.setFocus([]);
|
||||
this._onChangedVisibleCount.fire(this.elements.length);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue