Skip to content

Commit e4b9b75

Browse files
committed
1 parent 6a6df96 commit e4b9b75

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/vs/workbench/contrib/files/browser/editors/textFileEditor.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { localize } from 'vs/nls';
77
import { assertIsDefined } from 'vs/base/common/types';
88
import { IPathService } from 'vs/workbench/services/path/common/pathService';
99
import { toAction } from 'vs/base/common/actions';
10-
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID } from 'vs/workbench/contrib/files/common/files';
10+
import { VIEWLET_ID, TEXT_FILE_EDITOR_ID, BINARY_TEXT_FILE_MODE } from 'vs/workbench/contrib/files/common/files';
1111
import { ITextFileService, TextFileOperationError, TextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles';
1212
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
13-
import { IEditorOpenContext, EditorInputCapabilities, isTextEditorViewState } from 'vs/workbench/common/editor';
13+
import { IEditorOpenContext, EditorInputCapabilities, isTextEditorViewState, DEFAULT_EDITOR_ASSOCIATION } from 'vs/workbench/common/editor';
1414
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
1515
import { applyTextEditorOptions } from 'vs/workbench/common/editor/editorOptions';
1616
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
@@ -213,7 +213,7 @@ export class TextFileEditor extends BaseTextEditor<ICodeEditorViewState> {
213213
private openAsBinary(input: FileEditorInput, options: ITextEditorOptions | undefined): void {
214214
const defaultBinaryEditor = this.configurationService.getValue<string | undefined>('workbench.editor.defaultBinaryEditor');
215215
const groupToOpen = this.group ?? this.editorGroupService.activeGroup;
216-
const editorOptions = {
216+
let editorOptions = {
217217
...options,
218218
// Make sure to not steal away the currently active group
219219
// because we are triggering another openEditor() call
@@ -223,19 +223,25 @@ export class TextFileEditor extends BaseTextEditor<ICodeEditorViewState> {
223223
};
224224

225225
// If we the user setting specifies a default binary editor we use that
226-
if (defaultBinaryEditor && defaultBinaryEditor !== '') {
226+
if (defaultBinaryEditor && defaultBinaryEditor !== '' && defaultBinaryEditor !== DEFAULT_EDITOR_ASSOCIATION.id) {
227227
this.editorService.replaceEditors([{
228228
editor: input,
229229
replacement: { resource: input.resource, options: { ...editorOptions, override: defaultBinaryEditor } }
230230
}], groupToOpen);
231-
}
232-
233-
// Otherwise we mark file input for forced binary opening and reopen the file
234-
else {
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 };
239+
} else {
235240
input.setForceOpenAsBinary();
236-
237-
groupToOpen.openEditor(input, editorOptions);
238241
}
242+
243+
// Resolver wasn't needed proceed to oepn the editor as normal
244+
groupToOpen.openEditor(input, editorOptions);
239245
}
240246

241247
private async openAsFolder(input: FileEditorInput): Promise<void> {

0 commit comments

Comments
 (0)