I am using quickpick to display list of items and allowing user to do multiselect. I am using quickpick like this.
context.subscriptions.push(vscode.commands.registerCommand('command', async () => {
const list = await vscode.window.showQuickPick(filedsList, { ignoreFocusOut: true, canPickMany: true});
}));
I trying to make like if user previously selected some items in the quick pick and next time use opened this quick pick I want to preselect the previously selected values.
Is it feasible to do it in vscode extension development.
2
Answers
the object
vscode::QuickPickItem
has a propertypicked
There are two options. In both cases you’ll have to make
QuickPickItems
out of yourAccurevOperations.cpkFieldsList
as you cannot just pass strings as the first argument and use the pre-selection capability. It isn’t difficult to do this, just loop through thatAccurevOperations.cpkFieldsList
array and create objects with theQuickPickItem
properties you want, like:So you would use your logic to set the items you want pre-selected to have the
picked:true
object property. Thenshould show a QuickPick with your selected items.
The other option is to use the
createQuickPick
method instead, because with that you can use itsselectedItems
property. So starting with your array:You will have to create an array of objects to assign to the
selectedItems
property. Perhaps byfilter
ing thequickPickItems
array (from above) for thelabel
s you want pre-selected: