@@ -10,7 +10,7 @@ import { isCancellationError } from '../../../../../base/common/errors.js';
10
10
import { isEqual } from '../../../../../base/common/resources.js' ;
11
11
import * as strings from '../../../../../base/common/strings.js' ;
12
12
import { URI } from '../../../../../base/common/uri.js' ;
13
- import { IActiveCodeEditor , isCodeEditor , isDiffEditor } from '../../../../../editor/browser/editorBrowser.js' ;
13
+ import { getCodeEditor , IActiveCodeEditor } from '../../../../../editor/browser/editorBrowser.js' ;
14
14
import { IBulkEditService , ResourceTextEdit } from '../../../../../editor/browser/services/bulkEditService.js' ;
15
15
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js' ;
16
16
import { Range } from '../../../../../editor/common/core/range.js' ;
@@ -129,11 +129,14 @@ export class ApplyCodeBlockOperation {
129
129
if ( codemapperUri && ! isEqual ( activeEditorControl ?. getModel ( ) . uri , codemapperUri ) ) {
130
130
// reveal the target file
131
131
try {
132
- await this . editorService . openEditor ( { resource : codemapperUri } ) ;
133
-
134
- activeEditorControl = getEditableActiveCodeEditor ( this . editorService ) ;
135
- if ( activeEditorControl ) {
136
- this . tryToRevealCodeBlock ( activeEditorControl , context . code ) ;
132
+ const editorPane = await this . editorService . openEditor ( { resource : codemapperUri } ) ;
133
+ const codeEditor = getCodeEditor ( editorPane ?. getControl ( ) ) ;
134
+ if ( codeEditor && codeEditor . hasModel ( ) ) {
135
+ this . tryToRevealCodeBlock ( codeEditor , context . code ) ;
136
+ activeEditorControl = codeEditor ;
137
+ } else {
138
+ this . notify ( localize ( 'applyCodeBlock.errorOpeningFile' , "Failed to open {0} in a code editor." , codemapperUri . toString ( ) ) ) ;
139
+ return ;
137
140
}
138
141
} catch ( e ) {
139
142
this . logService . info ( '[ApplyCodeBlockOperation] error opening code mapper file' , codemapperUri , e ) ;
@@ -354,19 +357,20 @@ function getEditableActiveCodeEditor(editorService: IEditorService): IActiveCode
354
357
return activeCodeEditorInNotebook ;
355
358
}
356
359
357
- let activeEditorControl = editorService . activeTextEditorControl ;
358
- if ( isDiffEditor ( activeEditorControl ) ) {
359
- activeEditorControl = activeEditorControl . getOriginalEditor ( ) . hasTextFocus ( ) ? activeEditorControl . getOriginalEditor ( ) : activeEditorControl . getModifiedEditor ( ) ;
360
- }
361
-
362
- if ( ! isCodeEditor ( activeEditorControl ) ) {
363
- return undefined ;
360
+ let codeEditor = getCodeEditor ( editorService . activeTextEditorControl ) ;
361
+ if ( ! codeEditor ) {
362
+ for ( const editor of editorService . visibleTextEditorControls ) {
363
+ codeEditor = getCodeEditor ( editor ) ;
364
+ if ( codeEditor ) {
365
+ break ;
366
+ }
367
+ }
364
368
}
365
369
366
- if ( ! activeEditorControl . hasModel ( ) ) {
370
+ if ( ! codeEditor || ! codeEditor . hasModel ( ) ) {
367
371
return undefined ;
368
372
}
369
- return activeEditorControl ;
373
+ return codeEditor ;
370
374
}
371
375
372
376
function isReadOnly ( model : ITextModel , textFileService : ITextFileService ) : boolean {
0 commit comments