file editors - use a custom language when opening binary files as text (fix #131076)
This commit is contained in:
parent
827cc521d1
commit
d6eea3d342
|
@ -9,7 +9,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
|||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput';
|
||||
import { BINARY_FILE_EDITOR_ID } from 'vs/workbench/contrib/files/common/files';
|
||||
import { BINARY_FILE_EDITOR_ID, BINARY_TEXT_FILE_MODE } from 'vs/workbench/contrib/files/common/files';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { EditorResolution, IEditorOptions } from 'vs/platform/editor/common/editor';
|
||||
|
@ -78,15 +78,10 @@ export class BinaryFileEditor extends BaseBinaryResourceEditor {
|
|||
// If the result if a file editor, the user indicated to open
|
||||
// the binary file as text. As such we adjust the input for that.
|
||||
if (isEditorInputWithOptions(resolvedEditor)) {
|
||||
if (resolvedEditor.editor instanceof FileEditorInput) {
|
||||
resolvedEditor.editor.setForceOpenAsText();
|
||||
} else if (resolvedEditor.editor instanceof DiffEditorInput) {
|
||||
if (resolvedEditor.editor.original instanceof FileEditorInput) {
|
||||
resolvedEditor.editor.original.setForceOpenAsText();
|
||||
}
|
||||
|
||||
if (resolvedEditor.editor.modified instanceof FileEditorInput) {
|
||||
resolvedEditor.editor.modified.setForceOpenAsText();
|
||||
for (const editor of resolvedEditor.editor instanceof DiffEditorInput ? [resolvedEditor.editor.original, resolvedEditor.editor.modified] : [resolvedEditor.editor]) {
|
||||
if (editor instanceof FileEditorInput) {
|
||||
editor.setForceOpenAsText();
|
||||
editor.setPreferredMode(BINARY_TEXT_FILE_MODE); // https://github.com/microsoft/vscode/issues/131076
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { IConfigurationRegistry, Extensions as ConfigurationExtensions, Configur
|
|||
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
|
||||
import { IFileEditorInput, IEditorFactoryRegistry, EditorExtensions } from 'vs/workbench/common/editor';
|
||||
import { AutoSaveConfiguration, HotExitConfiguration, FILES_EXCLUDE_CONFIG, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/files';
|
||||
import { SortOrder, LexicographicOptions, FILE_EDITOR_INPUT_ID } from 'vs/workbench/contrib/files/common/files';
|
||||
import { SortOrder, LexicographicOptions, FILE_EDITOR_INPUT_ID, BINARY_TEXT_FILE_MODE } from 'vs/workbench/contrib/files/common/files';
|
||||
import { TextFileEditorTracker } from 'vs/workbench/contrib/files/browser/editors/textFileEditorTracker';
|
||||
import { TextFileSaveErrorHandler } from 'vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler';
|
||||
import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput';
|
||||
|
@ -33,6 +33,7 @@ import { UndoCommand, RedoCommand } from 'vs/editor/browser/editorExtensions';
|
|||
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
|
||||
import { IExplorerService } from 'vs/workbench/contrib/files/browser/files';
|
||||
import { FileEditorInputSerializer, FileEditorWorkingCopyEditorHandler } from 'vs/workbench/contrib/files/browser/editors/fileEditorHandler';
|
||||
import { ModesRegistry } from 'vs/editor/common/modes/modesRegistry';
|
||||
|
||||
class FileUriLabelContribution implements IWorkbenchContribution {
|
||||
|
||||
|
@ -444,3 +445,9 @@ RedoCommand.addImplementation(110, 'explorer', (accessor: ServicesAccessor) => {
|
|||
|
||||
return false;
|
||||
});
|
||||
|
||||
ModesRegistry.registerLanguage({
|
||||
id: BINARY_TEXT_FILE_MODE,
|
||||
aliases: ['Binary'],
|
||||
mimetypes: ['text/x-code-binary']
|
||||
});
|
||||
|
|
|
@ -73,6 +73,11 @@ export const FILE_EDITOR_INPUT_ID = 'workbench.editors.files.fileEditorInput';
|
|||
*/
|
||||
export const BINARY_FILE_EDITOR_ID = 'workbench.editors.files.binaryFileEditor';
|
||||
|
||||
/**
|
||||
* Language mode for binary files opened as text.
|
||||
*/
|
||||
export const BINARY_TEXT_FILE_MODE = 'code-text-binary';
|
||||
|
||||
export interface IFilesConfiguration extends PlatformIFilesConfiguration, IWorkbenchEditorConfiguration {
|
||||
explorer: {
|
||||
openEditors: {
|
||||
|
|
Loading…
Reference in a new issue