mirror of
https://github.com/Microsoft/vscode
synced 2024-10-13 14:57:14 +00:00
parent
0e02825e42
commit
8deb756222
|
@ -14,11 +14,11 @@ import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
|
|||
import { Action } from 'vs/base/common/actions';
|
||||
import { Language } from 'vs/base/common/platform';
|
||||
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
|
||||
import { IFileEditorInput, EncodingMode, IEncodingSupport, toResource, SideBySideEditorInput, IEditor as IBaseEditor, IEditorInput, SideBySideEditor, IModeSupport } from 'vs/workbench/common/editor';
|
||||
import { IFileEditorInput, EncodingMode, IEncodingSupport, toResource, SideBySideEditorInput, IEditor as IBaseEditor, IEditorInput, SideBySideEditor } from 'vs/workbench/common/editor';
|
||||
import { IDisposable, combinedDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
|
||||
import { IEditorAction } from 'vs/editor/common/editorCommon';
|
||||
import { EndOfLineSequence } from 'vs/editor/common/model';
|
||||
import { EndOfLineSequence, ITextModel } from 'vs/editor/common/model';
|
||||
import { IModelLanguageChangedEvent, IModelOptionsChangedEvent } from 'vs/editor/common/model/textModelEvents';
|
||||
import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/linesOperations';
|
||||
import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/indentation';
|
||||
|
@ -59,15 +59,7 @@ class SideBySideEditorEncodingSupport implements IEncodingSupport {
|
|||
}
|
||||
|
||||
setEncoding(encoding: string, mode: EncodingMode): void {
|
||||
[this.master, this.details].forEach(editor => editor.setEncoding(encoding, mode));
|
||||
}
|
||||
}
|
||||
|
||||
class SideBySideEditorModeSupport implements IModeSupport {
|
||||
constructor(private master: IModeSupport, private details: IModeSupport) { }
|
||||
|
||||
setMode(mode: ILanguageSelection): void {
|
||||
[this.master, this.details].forEach(editor => editor.setMode(mode));
|
||||
[this.master, this.details].forEach(s => s.setEncoding(encoding, mode));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +83,7 @@ function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport | nu
|
|||
}
|
||||
|
||||
// File or Resource Editor
|
||||
const encodingSupport = input as IFileEditorInput;
|
||||
let encodingSupport = input as IFileEditorInput;
|
||||
if (areFunctions(encodingSupport.setEncoding, encodingSupport.getEncoding)) {
|
||||
return encodingSupport;
|
||||
}
|
||||
|
@ -100,41 +92,14 @@ function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport | nu
|
|||
return null;
|
||||
}
|
||||
|
||||
function toEditorWithModeSupport(input: IEditorInput): IModeSupport | null {
|
||||
|
||||
// Untitled Editor
|
||||
if (input instanceof UntitledEditorInput) {
|
||||
return input;
|
||||
}
|
||||
|
||||
// Side by Side (diff) Editor
|
||||
if (input instanceof SideBySideEditorInput) {
|
||||
const masterModeSupport = toEditorWithModeSupport(input.master);
|
||||
const detailsModeSupport = toEditorWithModeSupport(input.details);
|
||||
|
||||
if (masterModeSupport && detailsModeSupport) {
|
||||
return new SideBySideEditorModeSupport(masterModeSupport, detailsModeSupport);
|
||||
}
|
||||
|
||||
return masterModeSupport;
|
||||
}
|
||||
|
||||
// File or Resource Editor
|
||||
const modeSupport = input as IFileEditorInput;
|
||||
if (typeof modeSupport.setMode === 'function') {
|
||||
return modeSupport;
|
||||
}
|
||||
|
||||
// Unsupported for any other editor
|
||||
return null;
|
||||
}
|
||||
|
||||
interface IEditorSelectionStatus {
|
||||
selections?: Selection[];
|
||||
charactersSelected?: number;
|
||||
}
|
||||
|
||||
class StateChange {
|
||||
_stateChangeBrand: void;
|
||||
|
||||
indentation: boolean = false;
|
||||
selectionStatus: boolean = false;
|
||||
mode: boolean = false;
|
||||
|
@ -155,7 +120,7 @@ class StateChange {
|
|||
this.metadata = this.metadata || other.metadata;
|
||||
}
|
||||
|
||||
hasChanges(): boolean {
|
||||
public hasChanges(): boolean {
|
||||
return this.indentation
|
||||
|| this.selectionStatus
|
||||
|| this.mode
|
||||
|
@ -214,49 +179,42 @@ class State {
|
|||
change.selectionStatus = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('indentation' in update) {
|
||||
if (this._indentation !== update.indentation) {
|
||||
this._indentation = update.indentation;
|
||||
change.indentation = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('mode' in update) {
|
||||
if (this._mode !== update.mode) {
|
||||
this._mode = update.mode;
|
||||
change.mode = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('encoding' in update) {
|
||||
if (this._encoding !== update.encoding) {
|
||||
this._encoding = update.encoding;
|
||||
change.encoding = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('EOL' in update) {
|
||||
if (this._EOL !== update.EOL) {
|
||||
this._EOL = update.EOL;
|
||||
change.EOL = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('tabFocusMode' in update) {
|
||||
if (this._tabFocusMode !== update.tabFocusMode) {
|
||||
this._tabFocusMode = update.tabFocusMode;
|
||||
change.tabFocusMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('screenReaderMode' in update) {
|
||||
if (this._screenReaderMode !== update.screenReaderMode) {
|
||||
this._screenReaderMode = update.screenReaderMode;
|
||||
change.screenReaderMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ('metadata' in update) {
|
||||
if (this._metadata !== update.metadata) {
|
||||
this._metadata = update.metadata;
|
||||
|
@ -278,6 +236,7 @@ const nlsTabFocusMode = nls.localize('tabFocusModeEnabled', "Tab Moves Focus");
|
|||
const nlsScreenReaderDetected = nls.localize('screenReaderDetected', "Screen Reader Optimized");
|
||||
const nlsScreenReaderDetectedTitle = nls.localize('screenReaderDetectedExtra', "If you are not using a Screen Reader, please change the setting `editor.accessibilitySupport` to \"off\".");
|
||||
|
||||
|
||||
class StatusBarItem {
|
||||
private _showing = true;
|
||||
|
||||
|
@ -289,15 +248,15 @@ class StatusBarItem {
|
|||
this.element.title = title;
|
||||
}
|
||||
|
||||
set textContent(value: string) {
|
||||
public set textContent(value: string) {
|
||||
this.element.textContent = value;
|
||||
}
|
||||
|
||||
set onclick(value: () => void) {
|
||||
public set onclick(value: () => void) {
|
||||
this.element.onclick = value;
|
||||
}
|
||||
|
||||
setVisible(shouldShow: boolean): void {
|
||||
public setVisible(shouldShow: boolean): void {
|
||||
if (shouldShow !== this._showing) {
|
||||
this._showing = shouldShow;
|
||||
this.element.style.display = shouldShow ? '' : 'none';
|
||||
|
@ -305,6 +264,7 @@ class StatusBarItem {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
export class EditorStatus implements IStatusbarItem {
|
||||
private state: State;
|
||||
private element: HTMLElement;
|
||||
|
@ -701,7 +661,7 @@ export class EditorStatus implements IStatusbarItem {
|
|||
this.updateState(update);
|
||||
}
|
||||
|
||||
private promptedScreenReader: boolean = false;
|
||||
private _promptedScreenReader: boolean = false;
|
||||
|
||||
private onScreenReaderModeChange(editorWidget: ICodeEditor | undefined): void {
|
||||
let screenReaderMode = false;
|
||||
|
@ -713,8 +673,8 @@ export class EditorStatus implements IStatusbarItem {
|
|||
const screenReaderConfiguration = this.configurationService.getValue<IEditorOptions>('editor').accessibilitySupport;
|
||||
if (screenReaderConfiguration === 'auto') {
|
||||
// show explanation
|
||||
if (!this.promptedScreenReader) {
|
||||
this.promptedScreenReader = true;
|
||||
if (!this._promptedScreenReader) {
|
||||
this._promptedScreenReader = true;
|
||||
setTimeout(() => {
|
||||
this.onScreenReaderModeClick();
|
||||
}, 100);
|
||||
|
@ -988,29 +948,44 @@ export class ChangeModeAction extends Action {
|
|||
|
||||
// Change mode for active editor
|
||||
const activeEditor = this.editorService.activeEditor;
|
||||
if (activeEditor) {
|
||||
const modeSupport = toEditorWithModeSupport(activeEditor);
|
||||
if (modeSupport) {
|
||||
|
||||
// Find mode
|
||||
let languageSelection: ILanguageSelection | undefined;
|
||||
if (pick === autoDetectMode) {
|
||||
if (textModel) {
|
||||
const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.MASTER });
|
||||
if (resource) {
|
||||
languageSelection = this.modeService.createByFilepathOrFirstLine(resource.fsPath, textModel.getLineContent(1));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
languageSelection = this.modeService.createByLanguageName(pick.label);
|
||||
const activeTextEditorWidget = this.editorService.activeTextEditorWidget;
|
||||
const models: ITextModel[] = [];
|
||||
if (isCodeEditor(activeTextEditorWidget)) {
|
||||
const codeEditorModel = activeTextEditorWidget.getModel();
|
||||
if (codeEditorModel) {
|
||||
models.push(codeEditorModel);
|
||||
}
|
||||
} else if (isDiffEditor(activeTextEditorWidget)) {
|
||||
const diffEditorModel = activeTextEditorWidget.getModel();
|
||||
if (diffEditorModel) {
|
||||
if (diffEditorModel.original) {
|
||||
models.push(diffEditorModel.original);
|
||||
}
|
||||
|
||||
// Change mode
|
||||
if (typeof languageSelection !== 'undefined') {
|
||||
modeSupport.setMode(languageSelection);
|
||||
if (diffEditorModel.modified) {
|
||||
models.push(diffEditorModel.modified);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find mode
|
||||
let languageSelection: ILanguageSelection | undefined;
|
||||
if (pick === autoDetectMode) {
|
||||
if (textModel) {
|
||||
const resource = toResource(activeEditor, { supportSideBySide: SideBySideEditor.MASTER });
|
||||
if (resource) {
|
||||
languageSelection = this.modeService.createByFilepathOrFirstLine(resource.fsPath, textModel.getLineContent(1));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
languageSelection = this.modeService.createByLanguageName(pick.label);
|
||||
}
|
||||
|
||||
// Change mode
|
||||
if (typeof languageSelection !== 'undefined') {
|
||||
for (const textModel of models) {
|
||||
this.modelService.setMode(textModel, languageSelection);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1184,7 +1159,6 @@ export class ChangeEncodingAction extends Action {
|
|||
if (!activeControl) {
|
||||
return this.quickInputService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]);
|
||||
}
|
||||
|
||||
const encodingSupport: IEncodingSupport | null = toEditorWithEncodingSupport(activeControl.input);
|
||||
if (!encodingSupport) {
|
||||
return this.quickInputService.pick([{ label: nls.localize('noFileEditor', "No file active at this time") }]);
|
||||
|
@ -1275,12 +1249,10 @@ export class ChangeEncodingAction extends Action {
|
|||
if (!encoding) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeControl = this.editorService.activeControl;
|
||||
if (!activeControl) {
|
||||
return;
|
||||
}
|
||||
|
||||
const encodingSupport = toEditorWithEncodingSupport(activeControl.input);
|
||||
if (typeof encoding.id !== 'undefined' && encodingSupport && encodingSupport.getEncoding() !== encoding.id) {
|
||||
encodingSupport.setEncoding(encoding.id, isReopenWithEncoding ? EncodingMode.Decode : EncodingMode.Encode); // Set new encoding
|
||||
|
|
|
@ -9,7 +9,6 @@ import { isUndefinedOrNull, withUndefinedAsNull } from 'vs/base/common/types';
|
|||
import { URI } from 'vs/base/common/uri';
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IEditor as ICodeEditor, IEditorViewState, ScrollType, IDiffEditor } from 'vs/editor/common/editorCommon';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
import { IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, IResourceInput } from 'vs/platform/editor/common/editor';
|
||||
import { IInstantiationService, IConstructorSignature0, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
@ -506,23 +505,12 @@ export interface IEncodingSupport {
|
|||
setEncoding(encoding: string, mode: EncodingMode): void;
|
||||
}
|
||||
|
||||
export interface IModeSupport {
|
||||
|
||||
/**
|
||||
* Sets the language mode of the input.
|
||||
*/
|
||||
setMode(languageSelection: ILanguageSelection): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a tagging interface to declare an editor input being capable of dealing with files. It is only used in the editor registry
|
||||
* to register this kind of input to the platform.
|
||||
*/
|
||||
export interface IFileEditorInput extends IEditorInput, IEncodingSupport, IModeSupport {
|
||||
export interface IFileEditorInput extends IEditorInput, IEncodingSupport {
|
||||
|
||||
/**
|
||||
* Gets the resource this editor is about.
|
||||
*/
|
||||
getResource(): URI;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,18 +3,17 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { EditorInput, ITextEditorModel, IModeSupport } from 'vs/workbench/common/editor';
|
||||
import { EditorInput, ITextEditorModel } from 'vs/workbench/common/editor';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IReference } from 'vs/base/common/lifecycle';
|
||||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
/**
|
||||
* A read-only text editor input whos contents are made of the provided resource that points to an existing
|
||||
* code editor model.
|
||||
*/
|
||||
export class ResourceEditorInput extends EditorInput implements IModeSupport {
|
||||
export class ResourceEditorInput extends EditorInput {
|
||||
|
||||
static readonly ID: string = 'workbench.editors.resourceEditorInput';
|
||||
|
||||
|
@ -63,18 +62,6 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
|
|||
}
|
||||
}
|
||||
|
||||
setMode(mode: ILanguageSelection): void {
|
||||
if (!this.modelReference) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modelReference.then(ref => {
|
||||
if (ref.object instanceof ResourceEditorModel) {
|
||||
ref.object.setMode(mode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resolve(): Promise<ITextEditorModel> {
|
||||
if (!this.modelReference) {
|
||||
this.modelReference = this.textModelResolverService.createModelReference(this.resource);
|
||||
|
@ -100,7 +87,7 @@ export class ResourceEditorInput extends EditorInput implements IModeSupport {
|
|||
}
|
||||
|
||||
if (otherInput instanceof ResourceEditorInput) {
|
||||
const otherResourceEditorInput = <ResourceEditorInput>otherInput;
|
||||
let otherResourceEditorInput = <ResourceEditorInput>otherInput;
|
||||
|
||||
// Compare by properties
|
||||
return otherResourceEditorInput.resource.toString() === this.resource.toString();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ITextModel, ITextBufferFactory, ITextSnapshot } from 'vs/editor/common/model';
|
||||
import { EditorModel, IModeSupport } from 'vs/workbench/common/editor';
|
||||
import { EditorModel } from 'vs/workbench/common/editor';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ITextEditorModel, IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { IModeService, ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
@ -14,7 +14,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
|
|||
/**
|
||||
* The base text editor model leverages the code editor model. This class is only intended to be subclassed and not instantiated.
|
||||
*/
|
||||
export abstract class BaseTextEditorModel extends EditorModel implements ITextEditorModel, IModeSupport {
|
||||
export abstract class BaseTextEditorModel extends EditorModel implements ITextEditorModel {
|
||||
|
||||
protected createdEditorModel: boolean;
|
||||
|
||||
|
@ -64,14 +64,6 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
|||
|
||||
abstract isReadonly(): boolean;
|
||||
|
||||
setMode(languageSelection: ILanguageSelection): void {
|
||||
if (!this.isResolved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.modelService.setMode(this.textEditorModel, languageSelection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the text editor model with the provided value, modeId (can be comma separated for multiple values) and optional resource URL.
|
||||
*/
|
||||
|
@ -126,7 +118,7 @@ export abstract class BaseTextEditorModel extends EditorModel implements ITextEd
|
|||
* Updates the text editor model with the provided value. If the value is the same as the model has, this is a no-op.
|
||||
*/
|
||||
protected updateTextEditorModel(newValue: ITextBufferFactory): void {
|
||||
if (!this.isResolved()) {
|
||||
if (!this.textEditorModel) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,19 +9,18 @@ import { memoize } from 'vs/base/common/decorators';
|
|||
import { PLAINTEXT_MODE_ID } from 'vs/editor/common/modes/modesRegistry';
|
||||
import { basename } from 'vs/base/common/path';
|
||||
import { basenameOrAuthority, dirname } from 'vs/base/common/resources';
|
||||
import { EditorInput, IEncodingSupport, EncodingMode, ConfirmResult, Verbosity, IModeSupport } from 'vs/workbench/common/editor';
|
||||
import { EditorInput, IEncodingSupport, EncodingMode, ConfirmResult, Verbosity } from 'vs/workbench/common/editor';
|
||||
import { UntitledEditorModel } from 'vs/workbench/common/editor/untitledEditorModel';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
/**
|
||||
* An editor input to be used for untitled text buffers.
|
||||
*/
|
||||
export class UntitledEditorInput extends EditorInput implements IEncodingSupport, IModeSupport {
|
||||
export class UntitledEditorInput extends EditorInput implements IEncodingSupport {
|
||||
|
||||
static readonly ID: string = 'workbench.editors.untitledEditorInput';
|
||||
|
||||
|
@ -59,6 +58,14 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
|
|||
return this.resource;
|
||||
}
|
||||
|
||||
getModeId(): string | null {
|
||||
if (this.cachedModel) {
|
||||
return this.cachedModel.getModeId();
|
||||
}
|
||||
|
||||
return this.modeId;
|
||||
}
|
||||
|
||||
getName(): string {
|
||||
return this.hasAssociatedFilePath ? basenameOrAuthority(this.resource) : this.resource.path;
|
||||
}
|
||||
|
@ -187,20 +194,6 @@ export class UntitledEditorInput extends EditorInput implements IEncodingSupport
|
|||
}
|
||||
}
|
||||
|
||||
setMode(mode: ILanguageSelection): void {
|
||||
if (this.cachedModel) {
|
||||
this.cachedModel.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
getModeId(): string | null {
|
||||
if (this.cachedModel) {
|
||||
return this.cachedModel.getModeId();
|
||||
}
|
||||
|
||||
return this.modeId;
|
||||
}
|
||||
|
||||
resolve(): Promise<UntitledEditorModel & IResolvedTextEditorModel> {
|
||||
|
||||
// Join a model resolve if we have had one before
|
||||
|
|
|
@ -18,7 +18,6 @@ import { IReference } from 'vs/base/common/lifecycle';
|
|||
import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
||||
import { FILE_EDITOR_INPUT_ID, TEXT_FILE_EDITOR_ID, BINARY_FILE_EDITOR_ID } from 'vs/workbench/contrib/files/common/files';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
/**
|
||||
* A file editor input is the input type for the file editor of file system resources.
|
||||
|
@ -98,13 +97,6 @@ export class FileEditorInput extends EditorInput implements IFileEditorInput {
|
|||
}
|
||||
}
|
||||
|
||||
setMode(mode: ILanguageSelection): void {
|
||||
const textModel = this.textFileService.models.get(this.resource);
|
||||
if (textModel) {
|
||||
textModel.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
setPreferredEncoding(encoding: string): void {
|
||||
this.preferredEncoding = encoding;
|
||||
this.forceOpenAsText = true; // encoding is a good hint to open the file as text
|
||||
|
|
|
@ -19,7 +19,6 @@ import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtil
|
|||
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
export class TestEditorControl extends BaseEditor {
|
||||
|
||||
|
@ -46,7 +45,6 @@ export class TestEditorInput extends EditorInput implements IFileEditorInput {
|
|||
setEncoding(encoding: string) { }
|
||||
getEncoding(): string { return null!; }
|
||||
setPreferredEncoding(encoding: string) { }
|
||||
setMode(mode: ILanguageSelection) { }
|
||||
getResource(): URI { return this.resource; }
|
||||
setForceOpenAsBinary(): void { }
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import { timeout } from 'vs/base/common/async';
|
|||
import { toResource } from 'vs/base/test/common/utils';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
export class TestEditorControl extends BaseEditor {
|
||||
|
||||
|
@ -57,7 +56,6 @@ export class TestEditorInput extends EditorInput implements IFileEditorInput {
|
|||
setEncoding(encoding: string) { }
|
||||
getEncoding(): string { return null!; }
|
||||
setPreferredEncoding(encoding: string) { }
|
||||
setMode(mode: ILanguageSelection) { }
|
||||
getResource(): URI { return this.resource; }
|
||||
setForceOpenAsBinary(): void { }
|
||||
setFailToOpen(): void {
|
||||
|
|
|
@ -66,8 +66,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
|||
private contentEncoding: string; // encoding as reported from disk
|
||||
private preferredEncoding: string; // encoding as chosen by the user
|
||||
|
||||
private preferredMode: ILanguageSelection; // mode as chosen by the user
|
||||
|
||||
private versionId: number;
|
||||
private bufferSavedVersionId: number;
|
||||
private blockModelContentChange: boolean;
|
||||
|
@ -209,22 +207,12 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
|||
return;
|
||||
}
|
||||
|
||||
if (this.preferredMode) {
|
||||
return; // do not override user choice
|
||||
}
|
||||
|
||||
const firstLineText = this.getFirstLineText(this.textEditorModel);
|
||||
const languageSelection = this.getOrCreateMode(this.modeService, undefined, firstLineText);
|
||||
|
||||
this.modelService.setMode(this.textEditorModel, languageSelection);
|
||||
}
|
||||
|
||||
setMode(languageSelection: ILanguageSelection): void {
|
||||
super.setMode(languageSelection);
|
||||
|
||||
this.preferredMode = languageSelection;
|
||||
}
|
||||
|
||||
async backup(target = this.resource): Promise<void> {
|
||||
if (this.isResolved()) {
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import { URI } from 'vs/base/common/uri';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IEncodingSupport, ConfirmResult, IRevertOptions, IModeSupport } from 'vs/workbench/common/editor';
|
||||
import { IEncodingSupport, ConfirmResult, IRevertOptions } from 'vs/workbench/common/editor';
|
||||
import { IBaseStatWithMetadata, IFileStatWithMetadata, IReadFileOptions, IWriteFileOptions, FileOperationError, FileOperationResult } from 'vs/platform/files/common/files';
|
||||
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ITextEditorModel, IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService';
|
||||
|
@ -443,7 +443,7 @@ export interface ILoadOptions {
|
|||
reason?: LoadReason;
|
||||
}
|
||||
|
||||
export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport, IModeSupport {
|
||||
export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport {
|
||||
|
||||
readonly onDidContentChange: Event<StateChange>;
|
||||
readonly onDidStateChange: Event<StateChange>;
|
||||
|
|
|
@ -20,7 +20,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
|||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ILanguageSelection } from 'vs/editor/common/services/modeService';
|
||||
|
||||
function inst(): IInstantiationService {
|
||||
let inst = new TestInstantiationService();
|
||||
|
@ -112,16 +111,27 @@ class TestFileEditorInput extends EditorInput implements IFileEditorInput {
|
|||
}
|
||||
getTypeId() { return 'testFileEditorInputForGroups'; }
|
||||
resolve(): Promise<IEditorModel> { return Promise.resolve(null!); }
|
||||
setEncoding(encoding: string) { }
|
||||
getEncoding(): string { return null!; }
|
||||
setPreferredEncoding(encoding: string) { }
|
||||
getResource(): URI { return this.resource; }
|
||||
setForceOpenAsBinary(): void { }
|
||||
setMode(mode: ILanguageSelection) { }
|
||||
|
||||
matches(other: TestFileEditorInput): boolean {
|
||||
return other && this.id === other.id && other instanceof TestFileEditorInput;
|
||||
}
|
||||
|
||||
setEncoding(encoding: string) {
|
||||
}
|
||||
|
||||
getEncoding(): string {
|
||||
return null!;
|
||||
}
|
||||
|
||||
setPreferredEncoding(encoding: string) {
|
||||
}
|
||||
|
||||
getResource(): URI {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
setForceOpenAsBinary(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function input(id = String(index++), nonSerializable?: boolean, resource?: URI): EditorInput {
|
||||
|
|
Loading…
Reference in a new issue