@@ -10,13 +10,13 @@ import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/edito
10
10
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions' ;
11
11
import { IBulkEditService , ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService' ;
12
12
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
13
+ import { EditOperation , ISingleEditOperation } from 'vs/editor/common/core/editOperation' ;
13
14
import { Range } from 'vs/editor/common/core/range' ;
14
15
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
15
- import { DocumentContextItem , TextEdit , WorkspaceEdit } from 'vs/editor/common/languages' ;
16
+ import { DocumentContextItem , WorkspaceEdit } from 'vs/editor/common/languages' ;
16
17
import { ILanguageService } from 'vs/editor/common/languages/language' ;
17
18
import { ITextModel } from 'vs/editor/common/model' ;
18
19
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures' ;
19
- import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
20
20
import { CopyAction } from 'vs/editor/contrib/clipboard/browser/clipboard' ;
21
21
import { localize2 } from 'vs/nls' ;
22
22
import { Action2 , MenuId , registerAction2 } from 'vs/platform/actions/common/actions' ;
@@ -607,6 +607,7 @@ export function registerChatCodeCompareBlockActions() {
607
607
f1 : false ,
608
608
category : CHAT_CATEGORY ,
609
609
icon : Codicon . check ,
610
+ precondition : EditorContextKeys . hasChanges ,
610
611
menu : {
611
612
id : MenuId . ChatCompareBlock ,
612
613
group : 'navigation'
@@ -615,19 +616,25 @@ export function registerChatCodeCompareBlockActions() {
615
616
}
616
617
617
618
async runWithContext ( accessor : ServicesAccessor , context : ICodeCompareBlockActionContext ) : Promise < any > {
618
- if ( ! isResponseVM ( context . element ) ) {
619
+ const model = context . diffEditor . getModel ( ) ;
620
+ if ( ! model ) {
619
621
return ;
620
622
}
621
- const modelService = accessor . get ( ITextModelService ) ;
622
- const ref = await modelService . createModelReference ( context . uri ) ;
623
- try {
624
- const edits = context . edits . map ( TextEdit . asEditOperation ) ;
625
- ref . object . textEditorModel . pushStackElement ( ) ;
626
- ref . object . textEditorModel . pushEditOperations ( null , edits , ( ) => null ) ;
627
- ref . object . textEditorModel . pushStackElement ( ) ;
628
- } finally {
629
- ref . dispose ( ) ;
623
+ const diff = context . diffEditor . getDiffComputationResult ( ) ;
624
+ if ( ! diff || diff . identical ) {
625
+ return ;
626
+ }
627
+
628
+ const edits : ISingleEditOperation [ ] = [ ] ;
629
+ for ( const item of diff . changes2 ) {
630
+ const range = item . original . toExclusiveRange ( ) ;
631
+ const newText = model . modified . getValueInRange ( item . modified . toExclusiveRange ( ) ) ;
632
+ edits . push ( EditOperation . replace ( range , newText ) ) ;
630
633
}
634
+
635
+ model . original . pushStackElement ( ) ;
636
+ model . original . pushEditOperations ( null , edits , ( ) => null ) ;
637
+ model . original . pushStackElement ( ) ;
631
638
}
632
639
} ) ;
633
640
0 commit comments