@@ -102,7 +102,7 @@ export const askToSelectPrompt = async (
102
102
}
103
103
104
104
// otherwise show the prompt file selection dialog
105
- const { viewsService , openerService } = options ;
105
+ const { openerService } = options ;
106
106
107
107
const quickPick = quickInputService . createQuickPick < WithUriValue < IQuickPickItem > > ( ) ;
108
108
quickPick . activeItems = activeItem ? [ activeItem ] : [ ] ;
@@ -126,36 +126,16 @@ export const askToSelectPrompt = async (
126
126
} ) ;
127
127
128
128
disposables . add ( quickPick . onDidAccept ( async ( event ) => {
129
+ const { selectedItems } = quickPick ;
129
130
const { alt, ctrlCmd } = quickPick . keyMods ;
130
131
131
- // TODO: @lego - refactor?
132
- // if `cmd`/`ctrl` key was pressed, open the selected prompt file(s)
132
+ // if `super` key was pressed, open the selected prompt file(s)
133
133
if ( ctrlCmd ) {
134
- for ( const selectedItem of quickPick . selectedItems ) {
135
- await openerService . open ( selectedItem . value ) ;
136
- }
137
-
138
- // if user submitted their selection, close the dialog
139
- if ( ! event . inBackground ) {
140
- disposables . dispose ( ) ;
141
- }
142
-
143
- return ;
134
+ return await openFiles ( selectedItems , openerService ) ;
144
135
}
145
136
146
137
// otherwise attach the selected prompt to a chat input
147
- lastActiveWidget = await getChatWidgetObject (
148
- options ,
149
- alt ,
150
- viewsService ,
151
- ) ;
152
-
153
- for ( const selectedItem of quickPick . selectedItems ) {
154
- lastActiveWidget
155
- . attachmentModel
156
- . promptInstructions
157
- . add ( selectedItem . value ) ;
158
- }
138
+ lastActiveWidget = await attachFiles ( selectedItems , options , alt ) ;
159
139
160
140
// if user submitted their selection, close the dialog
161
141
if ( ! event . inBackground ) {
@@ -216,18 +196,51 @@ const createPlaceholderText = (options: ISelectPromptOptions): string => {
216
196
return text ;
217
197
} ;
218
198
199
+ /**
200
+ * Opens provided files in the editor.
201
+ */
202
+ const openFiles = async (
203
+ files : readonly WithUriValue < IQuickPickItem > [ ] ,
204
+ openerService : IOpenerService ,
205
+ ) => {
206
+ for ( const file of files ) {
207
+ await openerService . open ( file . value ) ;
208
+ }
209
+ } ;
210
+
211
+ /**
212
+ * Attaches provided files to a chat input.
213
+ */
214
+ const attachFiles = async (
215
+ files : readonly WithUriValue < IQuickPickItem > [ ] ,
216
+ options : ISelectPromptOptions ,
217
+ altOption : boolean ,
218
+ ) : Promise < IChatWidget > => {
219
+ const widget = await getChatWidgetObject ( options , altOption ) ;
220
+
221
+ for ( const file of files ) {
222
+ widget
223
+ . attachmentModel
224
+ . promptInstructions
225
+ . add ( file . value ) ;
226
+ }
227
+
228
+ return widget ;
229
+ } ;
230
+
219
231
/**
220
232
* Gets a chat widget based on the provided {@link IChatAttachPromptActionOptions.widget widget}
221
233
* reference. If no widget reference is provided, the function will reveal a `chat panel` by default
222
234
* (either a last focused, or a new one), but if the {@link altOption} is set to `true`, a `chat edits`
223
235
* panel will be revealed instead (likewise either a last focused, or a new one).
236
+ *
237
+ * @throws if failed to reveal a chat widget.
224
238
*/
225
239
const getChatWidgetObject = async (
226
240
options : IChatAttachPromptActionOptions ,
227
241
altOption : boolean ,
228
- viewsService : IViewsService ,
229
242
) : Promise < IChatWidget > => {
230
- const { widget } = options ;
243
+ const { widget, viewsService } = options ;
231
244
232
245
// if no widget reference is present, the command was triggered from outside of
233
246
// an active chat input, so we reveal a chat widget window based on the `alt`
0 commit comments