From e95910adc961c0148ce37064158921fd84bb6943 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Mon, 30 Apr 2018 15:31:49 +0200 Subject: [PATCH] Eliminate CodeEditor --- src/vs/editor/browser/codeEditor.ts | 39 ------------------- .../editor/browser/widget/codeEditorWidget.ts | 11 ++++-- .../editor/browser/widget/diffEditorWidget.ts | 14 +++---- .../widget/embeddedCodeEditorWidget.ts | 6 +-- .../browser/standaloneCodeEditor.ts | 8 ++-- .../browser/parts/editor/textEditor.ts | 4 +- .../preferences/browser/preferencesEditor.ts | 12 +++--- .../electron-browser/dirtydiffDecorator.ts | 6 +-- .../electron-browser/walkThroughPart.ts | 8 ++-- 9 files changed, 37 insertions(+), 71 deletions(-) delete mode 100644 src/vs/editor/browser/codeEditor.ts diff --git a/src/vs/editor/browser/codeEditor.ts b/src/vs/editor/browser/codeEditor.ts deleted file mode 100644 index 160eac3591e..00000000000 --- a/src/vs/editor/browser/codeEditor.ts +++ /dev/null @@ -1,39 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; - -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { ICommandService } from 'vs/platform/commands/common/commands'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; -import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; -import { EditorAction, EditorExtensionsRegistry, IEditorContributionCtor } from 'vs/editor/browser/editorExtensions'; -import { IEditorOptions } from 'vs/editor/common/config/editorOptions'; -import { IThemeService } from 'vs/platform/theme/common/themeService'; -import { INotificationService } from 'vs/platform/notification/common/notification'; - -export class CodeEditor extends CodeEditorWidget { - - constructor( - domElement: HTMLElement, - options: IEditorOptions, - @IInstantiationService instantiationService: IInstantiationService, - @ICodeEditorService codeEditorService: ICodeEditorService, - @ICommandService commandService: ICommandService, - @IContextKeyService contextKeyService: IContextKeyService, - @IThemeService themeService: IThemeService, - @INotificationService notificationService: INotificationService - ) { - super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); - } - - protected _getContributions(): IEditorContributionCtor[] { - return EditorExtensionsRegistry.getEditorContributions(); - } - - protected _getActions(): EditorAction[] { - return EditorExtensionsRegistry.getEditorActions(); - } -} diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index a7492e4662c..e9feea81e13 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -52,7 +52,7 @@ import { ClassName } from 'vs/editor/common/model/intervalTree'; let EDITOR_ID = 0; -export abstract class CodeEditorWidget extends Disposable implements editorBrowser.ICodeEditor { +export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeEditor { //#region Eventing private readonly _onDidDispose: Emitter = this._register(new Emitter()); @@ -264,8 +264,13 @@ export abstract class CodeEditorWidget extends Disposable implements editorBrows return new Configuration(options, this.domElement); } - protected abstract _getContributions(): IEditorContributionCtor[]; - protected abstract _getActions(): EditorAction[]; + protected _getContributions(): IEditorContributionCtor[] { + return EditorExtensionsRegistry.getEditorContributions(); + } + + protected _getActions(): EditorAction[] { + return EditorExtensionsRegistry.getEditorActions(); + } public getId(): string { return this.getEditorType() + ':' + this.id; diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index 14a41c8c4d3..e766e3da62e 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -22,7 +22,7 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations'; import { renderViewLine, RenderLineInput } from 'vs/editor/common/viewLayout/viewLineRenderer'; import * as editorBrowser from 'vs/editor/browser/editorBrowser'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { Configuration } from 'vs/editor/browser/config/configuration'; import { Position, IPosition } from 'vs/editor/common/core/position'; import { Selection, ISelection } from 'vs/editor/common/core/selection'; @@ -85,7 +85,7 @@ class VisualEditorState { return allViewZones.filter((z) => !this._zonesMap[String(z.id)]); } - public clean(editor: CodeEditor): void { + public clean(editor: CodeEditorWidget): void { // (1) View zones if (this._zones.length > 0) { editor.changeViewZones((viewChangeAccessor: editorBrowser.IViewZoneChangeAccessor) => { @@ -101,7 +101,7 @@ class VisualEditorState { this._decorations = editor.deltaDecorations(this._decorations, []); } - public apply(editor: CodeEditor, overviewRuler: editorBrowser.IOverviewRuler, newDecorations: IEditorDiffDecorationsWithZones, restoreScrollState: boolean): void { + public apply(editor: CodeEditorWidget, overviewRuler: editorBrowser.IOverviewRuler, newDecorations: IEditorDiffDecorationsWithZones, restoreScrollState: boolean): void { const scrollState = restoreScrollState ? StableEditorScrollState.capture(editor) : null; @@ -160,12 +160,12 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE private _reviewHeight: number; private readonly _measureDomElementToken: number; - private originalEditor: CodeEditor; + private originalEditor: CodeEditorWidget; private _originalDomNode: HTMLElement; private _originalEditorState: VisualEditorState; private _originalOverviewRuler: editorBrowser.IOverviewRuler; - private modifiedEditor: CodeEditor; + private modifiedEditor: CodeEditorWidget; private _modifiedDomNode: HTMLElement; private _modifiedEditorState: VisualEditorState; private _modifiedOverviewRuler: editorBrowser.IOverviewRuler; @@ -468,8 +468,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE })); } - protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: editorOptions.IEditorOptions): CodeEditor { - return instantiationService.createInstance(CodeEditor, container, options); + protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: editorOptions.IEditorOptions): CodeEditorWidget { + return instantiationService.createInstance(CodeEditorWidget, container, options, false); } public dispose(): void { diff --git a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts index b24d4a9b62d..d459bb2087e 100644 --- a/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts +++ b/src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts @@ -10,14 +10,14 @@ import { ICommandService } from 'vs/platform/commands/common/commands'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { IConfigurationChangedEvent, IEditorOptions, IDiffEditorOptions } from 'vs/editor/common/config/editorOptions'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { INotificationService } from 'vs/platform/notification/common/notification'; -export class EmbeddedCodeEditorWidget extends CodeEditor { +export class EmbeddedCodeEditorWidget extends CodeEditorWidget { private _parentEditor: ICodeEditor; private _overwriteOptions: IEditorOptions; @@ -33,7 +33,7 @@ export class EmbeddedCodeEditorWidget extends CodeEditor { @IThemeService themeService: IThemeService, @INotificationService notificationService: INotificationService ) { - super(domElement, parentEditor.getRawConfiguration(), instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); + super(domElement, parentEditor.getRawConfiguration(), false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); this._parentEditor = parentEditor; this._overwriteOptions = options; diff --git a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts index 46b15a7bf8f..dd0969f9f16 100644 --- a/src/vs/editor/standalone/browser/standaloneCodeEditor.ts +++ b/src/vs/editor/standalone/browser/standaloneCodeEditor.ts @@ -18,7 +18,7 @@ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService'; import { StandaloneKeybindingService, applyConfigurationValues } from 'vs/editor/standalone/browser/simpleServices'; import { IEditorContextViewService } from 'vs/editor/standalone/browser/standaloneServices'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget'; import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService'; @@ -153,7 +153,7 @@ function createAriaDomNode() { /** * A code editor to be used both by the standalone editor and the standalone diff editor. */ -export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeEditor { +export class StandaloneCodeEditor extends CodeEditorWidget implements IStandaloneCodeEditor { private _standaloneKeybindingService: StandaloneKeybindingService; @@ -175,7 +175,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE ? nls.localize('accessibilityHelpMessageIE', "Press Ctrl+F1 for Accessibility Options.") : nls.localize('accessibilityHelpMessage', "Press Alt+F1 for Accessibility Options.") ); - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); + super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); if (keybindingService instanceof StandaloneKeybindingService) { this._standaloneKeybindingService = keybindingService; @@ -401,7 +401,7 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon super.updateOptions(newOptions); } - protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor { + protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditorWidget { return instantiationService.createInstance(StandaloneCodeEditor, container, options); } diff --git a/src/vs/workbench/browser/parts/editor/textEditor.ts b/src/vs/workbench/browser/parts/editor/textEditor.ts index f8342b510f5..0c0c2f2fa1d 100644 --- a/src/vs/workbench/browser/parts/editor/textEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textEditor.ts @@ -12,7 +12,7 @@ import * as objects from 'vs/base/common/objects'; import * as types from 'vs/base/common/types'; import * as errors from 'vs/base/common/errors'; import * as DOM from 'vs/base/browser/dom'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { EditorInput, EditorOptions, EditorViewStateMemento } from 'vs/workbench/common/editor'; import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor'; import { IEditorViewState, IEditor } from 'vs/editor/common/editorCommon'; @@ -182,7 +182,7 @@ export abstract class BaseTextEditor extends BaseEditor { protected createEditorControl(parent: HTMLElement, configuration: IEditorOptions): IEditor { // Use a getter for the instantiation service since some subclasses might use scoped instantiation services - return this.instantiationService.createInstance(CodeEditor, parent, configuration); + return this.instantiationService.createInstance(CodeEditorWidget, parent, configuration, false); } public setInput(input: EditorInput, options?: EditorOptions): TPromise { diff --git a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts index 7e9a04f3ab4..d3247d4fdc5 100644 --- a/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts +++ b/src/vs/workbench/parts/preferences/browser/preferencesEditor.ts @@ -20,7 +20,7 @@ import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorMo import { IEditorControl, Position } from 'vs/platform/editor/common/editor'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { BaseTextEditor } from 'vs/workbench/browser/parts/editor/textEditor'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IPreferencesSearchService, @@ -782,7 +782,7 @@ class SideBySidePreferencesWidget extends Widget { this.defaultPreferencesEditor = this._register(this.instantiationService.createInstance(DefaultPreferencesEditor)); this.defaultPreferencesEditor.create(this.defaultPreferencesEditorContainer); this.defaultPreferencesEditor.setVisible(true); - (this.defaultPreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.defaultPreferencesEditor); + (this.defaultPreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.defaultPreferencesEditor); this.editablePreferencesEditorContainer = DOM.append(parentElement, DOM.$('.editable-preferences-editor-container')); this.editablePreferencesEditorContainer.style.position = 'absolute'; @@ -879,7 +879,7 @@ class SideBySidePreferencesWidget extends Widget { this.editablePreferencesEditor = editor; this.editablePreferencesEditor.create(this.editablePreferencesEditorContainer); this.editablePreferencesEditor.setVisible(true); - (this.editablePreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.editablePreferencesEditor); + (this.editablePreferencesEditor.getControl()).onDidFocusEditor(() => this.lastFocusedEditor = this.editablePreferencesEditor); this.lastFocusedEditor = this.editablePreferencesEditor; return editor; @@ -887,7 +887,7 @@ class SideBySidePreferencesWidget extends Widget { private updateInput(editor: BaseEditor, input: EditorInput, editorContributionId: string, associatedPreferencesModelUri: URI, options: EditorOptions): TPromise> { return editor.setInput(input, options) - .then(() => (editor.getControl()).getContribution(editorContributionId).updatePreferencesRenderer(associatedPreferencesModelUri)); + .then(() => (editor.getControl()).getContribution(editorContributionId).updatePreferencesRenderer(associatedPreferencesModelUri)); } private createSash(parentElement: HTMLElement): void { @@ -966,7 +966,7 @@ export class DefaultPreferencesEditor extends BaseTextEditor { } public createEditorControl(parent: HTMLElement, configuration: IEditorOptions): editorCommon.IEditor { - const editor = this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parent, configuration); + const editor = this.instantiationService.createInstance(DefaultPreferencesCodeEditor, parent, configuration, false); // Inform user about editor being readonly if user starts type this.toUnbind.push(editor.onDidType(() => this.showReadonlyHint(editor))); @@ -1030,7 +1030,7 @@ export class DefaultPreferencesEditor extends BaseTextEditor { } } -class DefaultPreferencesCodeEditor extends CodeEditor { +class DefaultPreferencesCodeEditor extends CodeEditorWidget { protected _getContributions(): IEditorContributionCtor[] { let contributions = super._getContributions(); diff --git a/src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts b/src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts index 1a1374cd6c1..5f140409ece 100644 --- a/src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts +++ b/src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts @@ -13,7 +13,7 @@ import { IDisposable, dispose, toDisposable, empty as EmptyDisposable, combinedD import { TPromise } from 'vs/base/common/winjs.base'; import { Event, Emitter, anyEvent as anyEvent, filterEvent, once } from 'vs/base/common/event'; import * as ext from 'vs/workbench/common/contributions'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; @@ -1190,11 +1190,11 @@ export class DirtyDiffWorkbenchController implements ext.IWorkbenchContribution, .map(e => e.getControl()) // only interested in code editor widgets - .filter(c => c instanceof CodeEditor) + .filter(c => c instanceof CodeEditorWidget) // set model registry and map to models .map(editor => { - const codeEditor = editor as CodeEditor; + const codeEditor = editor as CodeEditorWidget; const controller = DirtyDiffController.get(codeEditor); controller.modelRegistry = this; return codeEditor.getModel(); diff --git a/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts b/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts index 8198c3ea31c..3f4b727db77 100644 --- a/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts +++ b/src/vs/workbench/parts/welcome/walkThrough/electron-browser/walkThroughPart.ts @@ -19,7 +19,7 @@ import { WalkThroughInput } from 'vs/workbench/parts/welcome/walkThrough/node/wa import { IOpenerService } from 'vs/platform/opener/common/opener'; import { marked } from 'vs/base/common/marked/marked'; import { IModelService } from 'vs/editor/common/services/modelService'; -import { CodeEditor } from 'vs/editor/browser/codeEditor'; +import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { localize } from 'vs/nls'; @@ -55,7 +55,7 @@ interface IWalkThroughEditorViewState { viewState: IViewState; } -class WalkThroughCodeEditor extends CodeEditor { +class WalkThroughCodeEditor extends CodeEditorWidget { constructor( domElement: HTMLElement, @@ -68,7 +68,7 @@ class WalkThroughCodeEditor extends CodeEditor { @IThemeService themeService: IThemeService, @INotificationService notificationService: INotificationService, ) { - super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); + super(domElement, options, false, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService); } getTelemetryData() { @@ -214,7 +214,7 @@ export class WalkThroughPart extends BaseEditor { size(this.content, dimension.width, dimension.height); this.updateSizeClasses(); this.contentDisposables.forEach(disposable => { - if (disposable instanceof CodeEditor) { + if (disposable instanceof CodeEditorWidget) { disposable.layout(); } }); -- GitLab