@@ -18,23 +18,17 @@ export interface ICheckboxQuickPickOptions {
18
18
confirmPlaceHolder : string ;
19
19
}
20
20
21
- const defaultOptions : ICheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
21
+ const defaultOptions : ICheckboxQuickPickOptions = { confirmPlaceHolder : defaultPlaceHolder } ;
22
22
23
- export function showCheckboxQuickPick (
23
+ export async function showCheckboxQuickPick (
24
24
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 ;
34
29
}
35
30
36
31
function getQuickPickItems ( items : ICheckboxQuickPickItem [ ] ) : vscode . QuickPickItem [ ] {
37
-
38
32
const quickPickItems : vscode . QuickPickItem [ ] = [ ] ;
39
33
quickPickItems . push ( { label : confirmItemLabel , description : "" } ) ;
40
34
@@ -48,40 +42,35 @@ function getQuickPickItems(items: ICheckboxQuickPickItem[]): vscode.QuickPickIte
48
42
return quickPickItems ;
49
43
}
50
44
51
- function showInner (
45
+ async function showInner (
52
46
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 ,
84
55
} ) ;
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 ) ;
85
74
}
86
75
87
76
function getItemIndex ( items : ICheckboxQuickPickItem [ ] , itemLabel : string ) : number {
0 commit comments