@@ -18,23 +18,17 @@ export interface ICheckboxQuickPickOptions {
1818 confirmPlaceHolder : string ;
1919}
2020
21- const defaultOptions : ICheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
21+ const defaultOptions : ICheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
2222
23- export function showCheckboxQuickPick (
23+ export async function showCheckboxQuickPick (
2424 items : ICheckboxQuickPickItem [ ] ,
25- options : ICheckboxQuickPickOptions = defaultOptions ) : Thenable < ICheckboxQuickPickItem [ ] > {
26-
27- return showInner ( items , options ) . then (
28- ( selectedItem ) => {
29- // We're mutating the original item list so just return it for now.
30- // If 'selectedItem' is undefined it means the user cancelled the
31- // inner showQuickPick UI so pass the undefined along.
32- return selectedItem !== undefined ? items : undefined ;
33- } ) ;
25+ options : ICheckboxQuickPickOptions = defaultOptions ) : Promise < ICheckboxQuickPickItem [ ] | undefined > {
26+
27+ const selectedItem = await showInner ( items , options ) ;
28+ return selectedItem !== undefined ? items : undefined ;
3429}
3530
3631function getQuickPickItems ( items : ICheckboxQuickPickItem [ ] ) : vscode . QuickPickItem [ ] {
37-
3832 const quickPickItems : vscode . QuickPickItem [ ] = [ ] ;
3933 quickPickItems . push ( { label : confirmItemLabel , description : "" } ) ;
4034
@@ -48,40 +42,35 @@ function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickIte
4842 return quickPickItems ;
4943}
5044
51- function showInner (
45+ async function showInner (
5246 items : ICheckboxQuickPickItem [ ] ,
53- options : ICheckboxQuickPickOptions ) : Thenable < vscode . QuickPickItem > {
54-
55- const quickPickThenable : Thenable < vscode . QuickPickItem > =
56- vscode . window . showQuickPick (
57- getQuickPickItems ( items ) ,
58- {
59- ignoreFocusOut : true ,
60- matchOnDescription : true ,
61- placeHolder : options . confirmPlaceHolder ,
62- } ) ;
63-
64- return quickPickThenable . then (
65- ( selection ) => {
66- if ( ! selection ) {
67- return Promise . resolve < vscode . QuickPickItem > ( undefined ) ;
68- }
69-
70- if ( selection . label === confirmItemLabel ) {
71- return selection ;
72- }
73-
74- const index : number = getItemIndex ( items , selection . label ) ;
75-
76- if ( index >= 0 ) {
77- toggleSelection ( items [ index ] ) ;
78- } else {
79- // tslint:disable-next-line:no-console
80- console . log ( `Couldn't find CheckboxQuickPickItem for label '${ selection . label } '` ) ;
81- }
82-
83- return showInner ( items , options ) ;
47+ options : ICheckboxQuickPickOptions ) : Promise < vscode . QuickPickItem | undefined > {
48+
49+ const selection = await vscode . window . showQuickPick (
50+ getQuickPickItems ( items ) ,
51+ {
52+ ignoreFocusOut : true ,
53+ matchOnDescription : true ,
54+ placeHolder : options . confirmPlaceHolder ,
8455 } ) ;
56+
57+ if ( selection === undefined ) {
58+ return undefined ;
59+ }
60+
61+ if ( selection . label === confirmItemLabel ) {
62+ return selection ;
63+ }
64+
65+ const index : number = getItemIndex ( items , selection . label ) ;
66+ if ( index >= 0 ) {
67+ toggleSelection ( items [ index ] ) ;
68+ } else {
69+ // tslint:disable-next-line:no-console
70+ console . log ( `Couldn't find CheckboxQuickPickItem for label '${ selection . label } '` ) ;
71+ }
72+
73+ return showInner ( items , options ) ;
8574}
8675
8776function getItemIndex ( items : ICheckboxQuickPickItem [ ] , itemLabel : string ) : number {
0 commit comments