@@ -33,7 +33,8 @@ import { IChatResponseModel } from '../../common/chatModel.js';
33
33
import { IDocumentDiff2 } from './chatEditingCodeEditorIntegration.js' ;
34
34
import { pendingRewriteMinimap } from './chatEditingModifiedFileEntry.js' ;
35
35
36
- type acceptedOrRejectedLines = { state : 'accepted' | 'rejected' ; lineCount : number ; hasRemainingEdits : boolean } ;
36
+ type affectedLines = { linesAdded : number ; linesRemoved : number ; lineCount : number ; hasRemainingEdits : boolean } ;
37
+ type acceptedOrRejectedLines = affectedLines & { state : 'accepted' | 'rejected' } ;
37
38
38
39
export class ChatEditingTextModelChangeService extends Disposable {
39
40
@@ -101,9 +102,9 @@ export class ChatEditingTextModelChangeService extends Disposable {
101
102
private readonly _didAcceptOrRejectLines = this . _register ( new Emitter < acceptedOrRejectedLines > ( ) ) ;
102
103
public readonly onDidAcceptOrRejectLines = this . _didAcceptOrRejectLines . event ;
103
104
104
- private notifyHunkAction ( state : 'accepted' | 'rejected' , lineCount : number , hasRemainingEdits : boolean ) {
105
- if ( lineCount > 0 ) {
106
- this . _didAcceptOrRejectLines . fire ( { state, lineCount , hasRemainingEdits } ) ;
105
+ private notifyHunkAction ( state : 'accepted' | 'rejected' , affectedLines : affectedLines ) {
106
+ if ( affectedLines . lineCount > 0 ) {
107
+ this . _didAcceptOrRejectLines . fire ( { state, ... affectedLines } ) ;
107
108
}
108
109
}
109
110
@@ -113,6 +114,8 @@ export class ChatEditingTextModelChangeService extends Disposable {
113
114
private _originalToModifiedEdit : StringEdit = StringEdit . empty ;
114
115
115
116
private lineChangeCount : number = 0 ;
117
+ private linesAdded : number = 0 ;
118
+ private linesRemoved : number = 0 ;
116
119
117
120
constructor (
118
121
private readonly originalModel : ITextModel ,
@@ -135,9 +138,15 @@ export class ChatEditingTextModelChangeService extends Disposable {
135
138
136
139
private updateLineChangeCount ( diff : IDocumentDiff ) {
137
140
this . lineChangeCount = 0 ;
141
+ this . linesAdded = 0 ;
142
+ this . linesRemoved = 0 ;
143
+
138
144
for ( const change of diff . changes ) {
139
145
const modifiedRange = change . modified . endLineNumberExclusive - change . modified . startLineNumber ;
146
+ this . linesAdded += Math . max ( 0 , modifiedRange ) ;
140
147
const originalRange = change . original . endLineNumberExclusive - change . original . startLineNumber ;
148
+ this . linesRemoved += Math . max ( 0 , originalRange ) ;
149
+
141
150
this . lineChangeCount += Math . max ( modifiedRange , originalRange ) ;
142
151
}
143
152
}
@@ -257,7 +266,7 @@ export class ChatEditingTextModelChangeService extends Disposable {
257
266
* Keeps the current modified document as the final contents.
258
267
*/
259
268
public keep ( ) {
260
- this . notifyHunkAction ( 'accepted' , this . lineChangeCount , false ) ;
269
+ this . notifyHunkAction ( 'accepted' , { linesAdded : this . linesAdded , linesRemoved : this . linesRemoved , lineCount : this . lineChangeCount , hasRemainingEdits : false } ) ;
261
270
this . originalModel . setValue ( this . modifiedModel . createSnapshot ( ) ) ;
262
271
this . _diffInfo . set ( nullDocumentDiff , undefined ) ;
263
272
this . _originalToModifiedEdit = StringEdit . empty ;
@@ -267,7 +276,7 @@ export class ChatEditingTextModelChangeService extends Disposable {
267
276
* Undoes the current modified document as the final contents.
268
277
*/
269
278
public undo ( ) {
270
- this . notifyHunkAction ( 'rejected' , this . lineChangeCount , false ) ;
279
+ this . notifyHunkAction ( 'rejected' , { linesAdded : this . linesAdded , linesRemoved : this . linesRemoved , lineCount : this . lineChangeCount , hasRemainingEdits : false } ) ;
271
280
this . modifiedModel . pushStackElement ( ) ;
272
281
this . _applyEdits ( [ ( EditOperation . replace ( this . modifiedModel . getFullModelRange ( ) , this . originalModel . getValue ( ) ) ) ] , EditSources . chatUndoEdits ( ) ) ;
273
282
this . modifiedModel . pushStackElement ( ) ;
@@ -379,12 +388,20 @@ export class ChatEditingTextModelChangeService extends Disposable {
379
388
const myDiffOperationId = ++ this . _diffOperationIds ;
380
389
await Promise . resolve ( this . _diffOperation ) ;
381
390
const previousCount = this . lineChangeCount ;
391
+ const previousAdded = this . linesAdded ;
392
+ const previousRemoved = this . linesRemoved ;
382
393
if ( this . _diffOperationIds === myDiffOperationId ) {
383
394
const thisDiffOperation = this . _updateDiffInfo ( ) ;
384
395
this . _diffOperation = thisDiffOperation ;
385
396
await thisDiffOperation ;
386
397
if ( notifyAction ) {
387
- this . notifyHunkAction ( notifyAction , previousCount - this . lineChangeCount , this . lineChangeCount > 0 ) ;
398
+ const affectedLines = {
399
+ linesAdded : previousAdded - this . linesAdded ,
400
+ linesRemoved : previousRemoved - this . linesRemoved ,
401
+ lineCount : previousCount - this . lineChangeCount ,
402
+ hasRemainingEdits : this . lineChangeCount > 0
403
+ } ;
404
+ this . notifyHunkAction ( notifyAction , affectedLines ) ;
388
405
}
389
406
}
390
407
}
0 commit comments