@@ -22,7 +22,9 @@ class MultiselectPrompt extends Prompt {
22
22
constructor ( opts = { } ) {
23
23
super ( opts ) ;
24
24
this . msg = opts . message ;
25
- this . cursor = opts . cursor || 0 ;
25
+ // set the cursor to the first non-heading
26
+ this . cursorStart = opts . choices . findIndex ( choice => ! choice . heading ) ;
27
+ this . cursor = opts . cursor || this . cursorStart ;
26
28
this . scrollIndex = opts . cursor || 0 ;
27
29
this . hint = opts . hint || '' ;
28
30
this . warn = opts . warn || '- This option is disabled -' ;
@@ -39,7 +41,8 @@ class MultiselectPrompt extends Prompt {
39
41
description : ch && ch . description ,
40
42
value : ch && ( ch . value === undefined ? idx : ch . value ) ,
41
43
selected : ch && ch . selected ,
42
- disabled : ch && ch . disabled
44
+ disabled : ch && ch . disabled ,
45
+ heading : ch && ch . heading
43
46
} ;
44
47
} ) ;
45
48
this . clear = clear ( '' , this . out . columns ) ;
@@ -50,7 +53,7 @@ class MultiselectPrompt extends Prompt {
50
53
51
54
reset ( ) {
52
55
this . value . map ( v => ! v . selected ) ;
53
- this . cursor = 0 ;
56
+ this . cursor = this . cursorStart ;
54
57
this . fire ( ) ;
55
58
this . render ( ) ;
56
59
}
@@ -88,7 +91,7 @@ class MultiselectPrompt extends Prompt {
88
91
}
89
92
90
93
first ( ) {
91
- this . cursor = 0 ;
94
+ this . cursor = this . cursorStart
92
95
this . render ( ) ;
93
96
}
94
97
@@ -98,23 +101,32 @@ class MultiselectPrompt extends Prompt {
98
101
}
99
102
next ( ) {
100
103
this . cursor = ( this . cursor + 1 ) % this . value . length ;
104
+ if ( this . value [ this . cursor ] . heading ) {
105
+ this . next ( ) ;
106
+ }
101
107
this . render ( ) ;
102
108
}
103
109
104
110
up ( ) {
105
- if ( this . cursor === 0 ) {
111
+ if ( this . cursor === this . cursorStart ) {
106
112
this . cursor = this . value . length - 1 ;
107
113
} else {
108
114
this . cursor -- ;
115
+ if ( this . value [ this . cursor ] . heading ) {
116
+ this . up ( ) ;
117
+ }
109
118
}
110
119
this . render ( ) ;
111
120
}
112
121
113
122
down ( ) {
114
123
if ( this . cursor === this . value . length - 1 ) {
115
- this . cursor = 0 ;
124
+ this . cursor = this . cursorStart ;
116
125
} else {
117
126
this . cursor ++ ;
127
+ if ( this . value [ this . cursor ] . heading ) {
128
+ this . down ( ) ;
129
+ }
118
130
}
119
131
this . render ( ) ;
120
132
}
@@ -150,7 +162,7 @@ class MultiselectPrompt extends Prompt {
150
162
}
151
163
152
164
const newSelected = ! this . value [ this . cursor ] . selected ;
153
- this . value . filter ( v => ! v . disabled ) . forEach ( v => v . selected = newSelected ) ;
165
+ this . value . filter ( v => ! v . disabled && ! v . heading ) . forEach ( v => v . selected = newSelected ) ;
154
166
this . render ( ) ;
155
167
}
156
168
@@ -184,7 +196,12 @@ class MultiselectPrompt extends Prompt {
184
196
185
197
if ( v . disabled ) {
186
198
title = cursor === i ? color . gray ( ) . underline ( v . title ) : color . strikethrough ( ) . gray ( v . title ) ;
187
- } else {
199
+ }
200
+ else if ( v . heading ) {
201
+ title = v . title
202
+ return title + color . gray ( desc || '' ) ;
203
+ }
204
+ else {
188
205
title = cursor === i ? color . cyan ( ) . underline ( v . title ) : v . title ;
189
206
if ( cursor === i && v . description ) {
190
207
desc = ` - ${ v . description } ` ;
0 commit comments