Last active
January 13, 2021 15:59
-
-
Save ecool/5d5042162194989772e50a0d15432489 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as vscode from 'vscode'; | |
export async function quickPickItem(items: string[]): Promise<string[]> { | |
const options = items.map(item => ({ label: item })); | |
return new Promise((resolve, _) => { | |
const quickPick = vscode.window.createQuickPick(); | |
const placeholder = "Select a item."; | |
quickPick.placeholder = placeholder; | |
quickPick.items = options; | |
quickPick.canSelectMany = true; | |
let selectedItems = []; | |
quickPick.onDidChangeSelection((selected) => { | |
selectedItems = selected; // string[] | |
}); | |
quickPick.onDidAccept(_ => { | |
// workaround for no activeItems when canSelectMany is true | |
resolve(selectedItems); | |
quickPick.hide(); | |
}); | |
quickPick.onDidHide(_ => quickPick.dispose()); | |
quickPick.show(); | |
}); | |
} | |
async function example() { | |
const result = await quickPickItem(['one', 'two', 'three']); | |
console.log(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment