mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-10 16:58:55 -05:00
create editor with real config (#18211)
This commit is contained in:
@@ -8,13 +8,14 @@
|
||||
import 'vs/css!./media/textdiffeditor';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import nls = require('vs/nls');
|
||||
import objects = require('vs/base/common/objects');
|
||||
import { Builder } from 'vs/base/browser/builder';
|
||||
import { Action, IAction } from 'vs/base/common/actions';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import types = require('vs/base/common/types');
|
||||
import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { IDiffEditorOptions, IEditorOptions } from 'vs/editor/common/editorCommon';
|
||||
import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor';
|
||||
import { TextEditorOptions, TextDiffEditorOptions, EditorModel, EditorInput, EditorOptions, TEXT_DIFF_EDITOR_ID } from 'vs/workbench/common/editor';
|
||||
import { StringEditorInput } from 'vs/workbench/common/editor/stringEditorInput';
|
||||
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
|
||||
@@ -66,7 +67,7 @@ export class TextDiffEditor extends BaseTextEditor {
|
||||
return nls.localize('textDiffEditor', "Text Diff Editor");
|
||||
}
|
||||
|
||||
public createEditorControl(parent: Builder): IDiffEditor {
|
||||
public createEditorControl(parent: Builder, configuration: IEditorOptions): IDiffEditor {
|
||||
|
||||
// Actions
|
||||
this.nextDiffAction = new NavigateAction(this, true);
|
||||
@@ -103,7 +104,7 @@ export class TextDiffEditor extends BaseTextEditor {
|
||||
// Create a special child of instantiator that will delegate all calls to openEditor() to the same diff editor if the input matches with the modified one
|
||||
const diffEditorInstantiator = this.instantiationService.createChild(new ServiceCollection([IWorkbenchEditorService, delegatingEditorService]));
|
||||
|
||||
return diffEditorInstantiator.createInstance(DiffEditorWidget, parent.getHTMLElement(), this.getCodeEditorOptions());
|
||||
return diffEditorInstantiator.createInstance(DiffEditorWidget, parent.getHTMLElement(), configuration);
|
||||
}
|
||||
|
||||
public setInput(input: EditorInput, options?: EditorOptions): TPromise<void> {
|
||||
@@ -167,9 +168,6 @@ export class TextDiffEditor extends BaseTextEditor {
|
||||
if (options && types.isFunction((<TextEditorOptions>options).apply)) {
|
||||
(<TextEditorOptions>options).apply(<IDiffEditor>diffEditor);
|
||||
}
|
||||
|
||||
// Apply options again because input has changed
|
||||
diffEditor.updateOptions(this.getCodeEditorOptions());
|
||||
}, (error) => {
|
||||
|
||||
// In case we tried to open a file and the response indicates that this is not a text file, fallback to binary diff.
|
||||
@@ -197,8 +195,19 @@ export class TextDiffEditor extends BaseTextEditor {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): IEditorOptions {
|
||||
const options: IDiffEditorOptions = super.getCodeEditorOptions();
|
||||
protected computeConfiguration(configuration: IEditorConfiguration): IEditorOptions {
|
||||
const editorConfiguration = super.computeConfiguration(configuration);
|
||||
|
||||
// Handle diff editor specially by merging in diffEditor configuration
|
||||
if (types.isObject(configuration.diffEditor)) {
|
||||
objects.mixin(editorConfiguration, configuration.diffEditor);
|
||||
}
|
||||
|
||||
return editorConfiguration;
|
||||
}
|
||||
|
||||
protected getConfigurationOverrides(): IEditorOptions {
|
||||
const options: IDiffEditorOptions = super.getConfigurationOverrides();
|
||||
|
||||
const input = this.input;
|
||||
if (input instanceof DiffEditorInput) {
|
||||
|
||||
@@ -14,7 +14,7 @@ import DOM = require('vs/base/browser/dom');
|
||||
import { CodeEditor } from 'vs/editor/browser/codeEditor';
|
||||
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
|
||||
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
|
||||
import { IEditorViewState, IEditor, IEditorOptions, EventType as EditorEventType, EditorType } from 'vs/editor/common/editorCommon';
|
||||
import { IEditorViewState, IEditor, IEditorOptions, EventType as EditorEventType } from 'vs/editor/common/editorCommon';
|
||||
import { Position } from 'vs/platform/editor/common/editor';
|
||||
import { IStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
@@ -33,7 +33,7 @@ interface ITextEditorViewState {
|
||||
2?: IEditorViewState;
|
||||
}
|
||||
|
||||
interface IEditorConfiguration {
|
||||
export interface IEditorConfiguration {
|
||||
editor: any;
|
||||
diffEditor: any;
|
||||
}
|
||||
@@ -87,20 +87,22 @@ export abstract class BaseTextEditor extends BaseEditor {
|
||||
return;
|
||||
}
|
||||
|
||||
// Specific editor options always overwrite user configuration
|
||||
const editorConfiguration = types.isObject(configuration.editor) ? objects.clone(configuration.editor) : Object.create(null);
|
||||
objects.assign(editorConfiguration, this.getCodeEditorOptions());
|
||||
|
||||
// Handle diff editor specially by merging in diffEditor configuration
|
||||
if (this.editorControl.getEditorType() === EditorType.IDiffEditor && types.isObject(configuration.diffEditor)) {
|
||||
objects.mixin(editorConfiguration, configuration.diffEditor);
|
||||
}
|
||||
const editorConfiguration = this.computeConfiguration(configuration);
|
||||
|
||||
// Apply to control
|
||||
this.editorControl.updateOptions(editorConfiguration);
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): IEditorOptions {
|
||||
protected computeConfiguration(configuration: IEditorConfiguration): IEditorOptions {
|
||||
|
||||
// Specific editor options always overwrite user configuration
|
||||
const editorConfiguration = types.isObject(configuration.editor) ? objects.clone(configuration.editor) : Object.create(null);
|
||||
objects.assign(editorConfiguration, this.getConfigurationOverrides());
|
||||
|
||||
return editorConfiguration;
|
||||
}
|
||||
|
||||
protected getConfigurationOverrides(): IEditorOptions {
|
||||
return {
|
||||
overviewRulerLanes: 3,
|
||||
lineNumbersMinChars: 3,
|
||||
@@ -113,26 +115,25 @@ export abstract class BaseTextEditor extends BaseEditor {
|
||||
|
||||
// Editor for Text
|
||||
this._editorContainer = parent;
|
||||
this.editorControl = this.createEditorControl(parent);
|
||||
this.editorControl = this.createEditorControl(parent, this.computeConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>()));
|
||||
|
||||
// Application & Editor focus change
|
||||
if (this.editorControl instanceof EventEmitter) {
|
||||
this.toUnbind.push(this.editorControl.addListener2(EditorEventType.EditorBlur, () => this.onEditorFocusLost()));
|
||||
}
|
||||
this.toUnbind.push(DOM.addDisposableListener(window, DOM.EventType.BLUR, () => this.onWindowFocusLost()));
|
||||
|
||||
// Configuration
|
||||
this.applyConfiguration(this.configurationService.getConfiguration<IEditorConfiguration>());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates and returns the text editor control to be used. Subclasses can override to
|
||||
* provide their own editor control that should be used (e.g. a DiffEditor).
|
||||
*
|
||||
* The passed in configuration object should be passed to the editor control when creating it.
|
||||
*/
|
||||
protected createEditorControl(parent: Builder): IEditor {
|
||||
protected createEditorControl(parent: Builder, configuration: IEditorOptions): IEditor {
|
||||
|
||||
// Use a getter for the instantiation service since some subclasses might use scoped instantiation services
|
||||
return this.instantiationService.createInstance(CodeEditor, parent.getHTMLElement(), this.getCodeEditorOptions());
|
||||
return this.instantiationService.createInstance(CodeEditor, parent.getHTMLElement(), configuration);
|
||||
}
|
||||
|
||||
private onEditorFocusLost(): void {
|
||||
@@ -170,7 +171,10 @@ export abstract class BaseTextEditor extends BaseEditor {
|
||||
|
||||
public setInput(input: EditorInput, options?: EditorOptions): TPromise<void> {
|
||||
return super.setInput(input, options).then(() => {
|
||||
this.editorControl.updateOptions(this.getCodeEditorOptions()); // support input specific editor options
|
||||
|
||||
// Update editor options after having set the input. We do this because there can be
|
||||
// editor input specific options (e.g. an ARIA label depending on the input showing)
|
||||
this.editorControl.updateOptions(this.getConfigurationOverrides());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -111,9 +111,6 @@ export class TextResourceEditor extends BaseTextEditor {
|
||||
if (!optionsGotApplied) {
|
||||
this.restoreViewState(input);
|
||||
}
|
||||
|
||||
// Apply options again because input has changed
|
||||
textEditor.updateOptions(this.getCodeEditorOptions());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,8 +123,8 @@ export class TextResourceEditor extends BaseTextEditor {
|
||||
}
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): IEditorOptions {
|
||||
const options = super.getCodeEditorOptions();
|
||||
protected getConfigurationOverrides(): IEditorOptions {
|
||||
const options = super.getConfigurationOverrides();
|
||||
|
||||
const input = this.input;
|
||||
const isUntitled = input instanceof UntitledEditorInput;
|
||||
|
||||
@@ -206,8 +206,8 @@ export class TextFileEditor extends BaseTextEditor {
|
||||
return true; // in any case we handled it
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): IEditorOptions {
|
||||
const options = super.getCodeEditorOptions();
|
||||
protected getConfigurationOverrides(): IEditorOptions {
|
||||
const options = super.getConfigurationOverrides();
|
||||
|
||||
const input = this.input;
|
||||
const inputName = input && input.getName();
|
||||
|
||||
@@ -75,8 +75,8 @@ export class OutputPanel extends TextResourceEditor {
|
||||
return super.getActionItem(action);
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): IEditorOptions {
|
||||
const options = super.getCodeEditorOptions();
|
||||
protected getConfigurationOverrides(): IEditorOptions {
|
||||
const options = super.getConfigurationOverrides();
|
||||
options.wrappingColumn = 0; // all output editors wrap
|
||||
options.lineNumbers = 'off'; // all output editors hide line numbers
|
||||
options.glyphMargin = false;
|
||||
|
||||
@@ -120,20 +120,20 @@ export class DefaultPreferencesEditor extends BaseTextEditor {
|
||||
this.delayedFilterLogging = new Delayer<void>(1000);
|
||||
}
|
||||
|
||||
public createEditorControl(parent: Builder): editorCommon.IEditor {
|
||||
public createEditorControl(parent: Builder, configuration: editorCommon.IEditorOptions): editorCommon.IEditor {
|
||||
const parentContainer = parent.getHTMLElement();
|
||||
|
||||
this.defaultSettingHeaderWidget = this._register(this.instantiationService.createInstance(DefaultSettingsHeaderWidget, parentContainer));
|
||||
this._register(this.defaultSettingHeaderWidget.onDidChange(value => this.filterPreferences(value)));
|
||||
this._register(this.defaultSettingHeaderWidget.onEnter(value => this.focusNextPreference()));
|
||||
|
||||
const defaultPreferencesEditor = this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parentContainer, this.getCodeEditorOptions());
|
||||
const defaultPreferencesEditor = this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parentContainer, configuration);
|
||||
|
||||
return defaultPreferencesEditor;
|
||||
}
|
||||
|
||||
protected getCodeEditorOptions(): editorCommon.IEditorOptions {
|
||||
const options = super.getCodeEditorOptions();
|
||||
protected getConfigurationOverrides(): editorCommon.IEditorOptions {
|
||||
const options = super.getConfigurationOverrides();
|
||||
options.readOnly = true;
|
||||
if (this.input) {
|
||||
options.lineNumbers = 'off';
|
||||
|
||||
Reference in New Issue
Block a user