@@ -24,7 +24,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
24
24
import { IThemeService } from 'vs/platform/theme/common/themeService' ;
25
25
import { ICodeEditorViewState , ScrollType } from 'vs/editor/common/editorCommon' ;
26
26
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
27
- import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
27
+ import { IEditorGroup , IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
28
28
import { CancellationToken } from 'vs/base/common/cancellation' ;
29
29
import { IErrorWithActions } from 'vs/base/common/errorMessage' ;
30
30
import { EditorActivation , ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
@@ -212,7 +212,8 @@ export class TextFileEditor extends BaseTextEditor<ICodeEditorViewState> {
212
212
213
213
private openAsBinary ( input : FileEditorInput , options : ITextEditorOptions | undefined ) : void {
214
214
const defaultBinaryEditor = this . configurationService . getValue < string | undefined > ( 'workbench.editor.defaultBinaryEditor' ) ;
215
- const groupToOpen = this . group ?? this . editorGroupService . activeGroup ;
215
+ const group = this . group ?? this . editorGroupService . activeGroup ;
216
+
216
217
let editorOptions = {
217
218
...options ,
218
219
// Make sure to not steal away the currently active group
@@ -222,26 +223,43 @@ export class TextFileEditor extends BaseTextEditor<ICodeEditorViewState> {
222
223
activation : EditorActivation . PRESERVE
223
224
} ;
224
225
225
- // If we the user setting specifies a default binary editor we use that
226
+ // Check configuration and determine whether we open the binary
227
+ // file input in a different editor or going through the same
228
+ // editor.
229
+ // Going through the same editor is debt, and a better solution
230
+ // would be to introduce a real editor for the binary case
231
+ // and avoid enforcing binary or text on the file editor input.
232
+
226
233
if ( defaultBinaryEditor && defaultBinaryEditor !== '' && defaultBinaryEditor !== DEFAULT_EDITOR_ASSOCIATION . id ) {
227
- this . editorService . replaceEditors ( [ {
228
- editor : input ,
229
- replacement : { resource : input . resource , options : { ...editorOptions , override : defaultBinaryEditor } }
230
- } ] , groupToOpen ) ;
231
- // Replace is completed, don't do any further text input options as it's no longer text.
232
- return ;
233
- } else if ( defaultBinaryEditor === DEFAULT_EDITOR_ASSOCIATION . id ) {
234
- input . setForceOpenAsText ( ) ;
235
- // Distinguish between plain text and plain text binary
236
- input . setPreferredLanguageId ( BINARY_TEXT_FILE_MODE ) ;
237
- // Same pane and same input, must force reload to clear cached state
238
- editorOptions = { ...editorOptions , forceReload : true } ;
234
+ this . doOpenAsBinaryInDifferentEditor ( group , defaultBinaryEditor , input , editorOptions ) ;
239
235
} else {
240
- input . setForceOpenAsBinary ( ) ;
236
+ this . doOpenAsBinaryInSameEditor ( group , defaultBinaryEditor , input , editorOptions ) ;
237
+ }
238
+ }
239
+
240
+ private doOpenAsBinaryInDifferentEditor ( group : IEditorGroup , editorId : string | undefined , editor : FileEditorInput , editorOptions : ITextEditorOptions ) : void {
241
+ this . editorService . replaceEditors ( [ {
242
+ editor,
243
+ replacement : { resource : editor . resource , options : { ...editorOptions , override : editorId } }
244
+ } ] , group ) ;
245
+ }
246
+
247
+ private doOpenAsBinaryInSameEditor ( group : IEditorGroup , editorId : string | undefined , editor : FileEditorInput , editorOptions : ITextEditorOptions ) : void {
248
+
249
+ // Open binary as text
250
+ if ( editorId === DEFAULT_EDITOR_ASSOCIATION . id ) {
251
+ editor . setForceOpenAsText ( ) ;
252
+ editor . setPreferredLanguageId ( BINARY_TEXT_FILE_MODE ) ; // https://github.com/microsoft/vscode/issues/131076
253
+
254
+ editorOptions = { ...editorOptions , forceReload : true } ; // Same pane and same input, must force reload to clear cached state
255
+ }
256
+
257
+ // Open as binary
258
+ else {
259
+ editor . setForceOpenAsBinary ( ) ;
241
260
}
242
261
243
- // Resolver wasn't needed proceed to oepn the editor as normal
244
- groupToOpen . openEditor ( input , editorOptions ) ;
262
+ group . openEditor ( editor , editorOptions ) ;
245
263
}
246
264
247
265
private async openAsFolder ( input : FileEditorInput ) : Promise < void > {
0 commit comments