@@ -222,6 +222,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
222
222
}
223
223
224
224
private _indexOfLastAttachedContextDeletedWithKeyboard : number ;
225
+ private _indexOfLastOpenedContext : number ;
225
226
226
227
private _implicitContext : ChatImplicitContext | undefined ;
227
228
public get implicitContext ( ) : ChatImplicitContext | undefined {
@@ -409,6 +410,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
409
410
this . _onDidAcceptFollowup = this . _register ( new Emitter < { followup : IChatFollowup ; response : IChatResponseViewModel | undefined } > ( ) ) ;
410
411
this . onDidAcceptFollowup = this . _onDidAcceptFollowup . event ;
411
412
this . _indexOfLastAttachedContextDeletedWithKeyboard = - 1 ;
413
+ this . _indexOfLastOpenedContext = - 1 ;
412
414
this . _onDidChangeVisibility = this . _register ( new Emitter < boolean > ( ) ) ;
413
415
this . _contextResourceLabels = this . instantiationService . createInstance ( ResourceLabels , { onDidChangeVisibility : this . _onDidChangeVisibility . event } ) ;
414
416
this . inputEditorHeight = 0 ;
@@ -977,12 +979,18 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
977
979
) ;
978
980
979
981
this . _register ( this . _implicitContext . onDidChangeValue ( ( ) => {
982
+ this . _indexOfLastAttachedContextDeletedWithKeyboard = - 1 ;
980
983
this . _handleAttachedContextChange ( ) ;
981
984
} ) ) ;
982
985
}
983
986
984
987
this . renderAttachedContext ( ) ;
985
- this . _register ( this . _attachmentModel . onDidChange ( ( ) => this . _handleAttachedContextChange ( ) ) ) ;
988
+ this . _register ( this . _attachmentModel . onDidChange ( ( e ) => {
989
+ if ( e . added . length > 0 ) {
990
+ this . _indexOfLastAttachedContextDeletedWithKeyboard = - 1 ;
991
+ }
992
+ this . _handleAttachedContextChange ( ) ;
993
+ } ) ) ;
986
994
this . renderChatEditingSessionState ( null ) ;
987
995
988
996
if ( this . options . renderWorkingSet ) {
@@ -1239,6 +1247,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
1239
1247
dom . setVisibility ( hasAttachments , this . attachedContextContainer ) ;
1240
1248
if ( ! attachments . length ) {
1241
1249
this . _indexOfLastAttachedContextDeletedWithKeyboard = - 1 ;
1250
+ this . _indexOfLastOpenedContext = - 1 ;
1242
1251
}
1243
1252
1244
1253
this . promptFileAttached . set ( this . hasPromptFileAttachments ) ;
@@ -1247,7 +1256,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
1247
1256
for ( const [ index , attachment ] of attachments ) {
1248
1257
const resource = URI . isUri ( attachment . value ) ? attachment . value : attachment . value && typeof attachment . value === 'object' && 'uri' in attachment . value && URI . isUri ( attachment . value . uri ) ? attachment . value . uri : undefined ;
1249
1258
const range = attachment . value && typeof attachment . value === 'object' && 'range' in attachment . value && Range . isIRange ( attachment . value . range ) ? attachment . value . range : undefined ;
1250
- const shouldFocusClearButton = index === Math . min ( this . _indexOfLastAttachedContextDeletedWithKeyboard , this . attachmentModel . size - 1 ) ;
1259
+ const shouldFocusClearButton = index === Math . min ( this . _indexOfLastAttachedContextDeletedWithKeyboard , this . attachmentModel . size - 1 ) && this . _indexOfLastAttachedContextDeletedWithKeyboard > - 1 ;
1251
1260
1252
1261
let attachmentWidget ;
1253
1262
const options = { shouldFocusClearButton, supportsDeletion : true } ;
@@ -1268,10 +1277,23 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
1268
1277
} else {
1269
1278
attachmentWidget = this . instantiationService . createInstance ( DefaultChatAttachmentWidget , resource , range , attachment , undefined , this . _currentLanguageModel , options , container , this . _contextResourceLabels , hoverDelegate ) ;
1270
1279
}
1280
+
1281
+ if ( shouldFocusClearButton ) {
1282
+ attachmentWidget . element . focus ( ) ;
1283
+ }
1284
+
1285
+ if ( index === Math . min ( this . _indexOfLastOpenedContext , this . attachmentModel . size - 1 ) ) {
1286
+ attachmentWidget . element . focus ( ) ;
1287
+ }
1288
+
1271
1289
store . add ( attachmentWidget ) ;
1272
1290
store . add ( attachmentWidget . onDidDelete ( e => {
1273
1291
this . handleAttachmentDeletion ( e , index , attachment ) ;
1274
1292
} ) ) ;
1293
+
1294
+ store . add ( attachmentWidget . onDidOpen ( e => {
1295
+ this . handleAttachmentOpen ( index , attachment ) ;
1296
+ } ) ) ;
1275
1297
}
1276
1298
1277
1299
const implicitUri = this . implicitContext ?. value ;
@@ -1290,6 +1312,8 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
1290
1312
if ( oldHeight !== this . attachmentsContainer . offsetHeight ) {
1291
1313
this . _onDidChangeHeight . fire ( ) ;
1292
1314
}
1315
+
1316
+ this . _indexOfLastOpenedContext = - 1 ;
1293
1317
}
1294
1318
1295
1319
private handleAttachmentDeletion ( e : KeyboardEvent | unknown , index : number , attachment : IChatRequestVariableEntry ) {
@@ -1309,6 +1333,15 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
1309
1333
this . renderAttachedContext ( ) ;
1310
1334
}
1311
1335
1336
+ private handleAttachmentOpen ( index : number , attachment : IChatRequestVariableEntry ) : void {
1337
+ this . _indexOfLastOpenedContext = index ;
1338
+ this . _indexOfLastAttachedContextDeletedWithKeyboard = - 1 ;
1339
+
1340
+ if ( this . _attachmentModel . size === 0 ) {
1341
+ this . focus ( ) ;
1342
+ }
1343
+ }
1344
+
1312
1345
private handleAttachmentNavigation ( e : StandardKeyboardEvent ) : void {
1313
1346
if ( ! e . equals ( KeyCode . LeftArrow ) && ! e . equals ( KeyCode . RightArrow ) ) {
1314
1347
return ;
0 commit comments