@@ -168,44 +168,25 @@ export class ChatWidget extends Disposable implements IChatWidget {
168
168
this . inputPart . focus ( ) ;
169
169
}
170
170
171
- focusNext ( id : string ) : void {
171
+ focusWithId ( id : string , type : 'next' | 'previous' ) : void {
172
172
const items = this . viewModel ?. getItems ( ) ;
173
173
if ( ! items ) {
174
174
return ;
175
175
}
176
- const focusedElement = items ?. find ( i => i . id === id ) as any as IChatResponseViewModel ;
177
- const responseItems = items ?. filter ( i => isResponseVM ( i ) ) ;
176
+ const focusedElement = items . find ( i => i . id === id ) ;
178
177
if ( ! focusedElement ) {
179
178
return ;
180
179
}
181
- const currentlyFocusedIndex = responseItems ?. indexOf ( focusedElement ) ;
182
- if ( currentlyFocusedIndex === undefined || ! responseItems ) {
183
- return ;
184
- }
185
- if ( currentlyFocusedIndex === responseItems . length - 1 ) {
186
- return ;
187
- }
188
- this . focus ( responseItems [ currentlyFocusedIndex + 1 ] , true ) ;
189
- }
190
-
191
- focusPrevious ( id : string ) : void {
192
- const items = this . viewModel ?. getItems ( ) ;
193
- if ( ! items ) {
194
- return ;
195
- }
196
- const focusedElement = items . find ( i => i . id === id ) as any as IChatResponseViewModel ;
197
180
const responseItems = items . filter ( i => isResponseVM ( i ) ) ;
198
- if ( ! focusedElement ) {
199
- return ;
200
- }
201
181
const currentlyFocusedIndex = responseItems ?. indexOf ( focusedElement ) ;
202
- if ( ! currentlyFocusedIndex || ! responseItems ) {
182
+ if ( currentlyFocusedIndex === undefined || ! responseItems ) {
203
183
return ;
204
184
}
205
- if ( currentlyFocusedIndex - 1 < 0 ) {
185
+ const indexToFocus = type === 'next' ? currentlyFocusedIndex + 1 : currentlyFocusedIndex - 1 ;
186
+ if ( indexToFocus < 0 || indexToFocus === responseItems . length - 1 ) {
206
187
return ;
207
188
}
208
- this . focus ( responseItems [ currentlyFocusedIndex - 1 ] , true ) ;
189
+ this . focus ( responseItems [ indexToFocus ] ) ;
209
190
}
210
191
211
192
private onDidChangeItems ( ) {
@@ -427,17 +408,15 @@ export class ChatWidget extends Disposable implements IChatWidget {
427
408
this . tree . reveal ( item ) ;
428
409
}
429
410
430
- focus ( item : ChatTreeItem , noDomFocus ?: boolean ) : void {
411
+ focus ( item : ChatTreeItem ) : void {
431
412
const items = this . tree . getNode ( null ) . children ;
432
413
const node = items . find ( i => i . element ?. id === item . id ) ;
433
414
if ( ! node ) {
434
415
return ;
435
416
}
436
417
437
418
this . tree . setFocus ( [ node . element ] ) ;
438
- // if (!noDomFocus) {
439
419
this . tree . domFocus ( ) ;
440
- // }
441
420
}
442
421
443
422
async acceptInput ( query ?: string | IChatReplyFollowup ) : Promise < void > {
0 commit comments