diff --git a/src/vs/base/common/eventEmitter.ts b/src/vs/base/common/eventEmitter.ts index 83e1493a68b..b9217b1c679 100644 --- a/src/vs/base/common/eventEmitter.ts +++ b/src/vs/base/common/eventEmitter.ts @@ -26,10 +26,13 @@ export interface BulkListenerCallback { (value: EmitterEvent[]): void; } -export interface IEventEmitter extends IDisposable { +export interface IBaseEventEmitter { + addBulkListener(listener: BulkListenerCallback): IDisposable; +} + +export interface IEventEmitter extends IBaseEventEmitter, IDisposable { addListener(eventType: string, listener: ListenerCallback): IDisposable; addOneTimeListener(eventType: string, listener: ListenerCallback): IDisposable; - addBulkListener(listener: BulkListenerCallback): IDisposable; addEmitter(eventEmitter: IEventEmitter): IDisposable; } @@ -120,7 +123,7 @@ export class EventEmitter implements IEventEmitter { }; } - public addEmitter(eventEmitter: IEventEmitter): IDisposable { + public addEmitter(eventEmitter: IBaseEventEmitter): IDisposable { return eventEmitter.addBulkListener((events: EmitterEvent[]): void => { if (this._deferredCnt === 0) { this._emitEvents(events); diff --git a/src/vs/editor/browser/standalone/simpleServices.ts b/src/vs/editor/browser/standalone/simpleServices.ts index 78a7241411f..0e5a0d7587b 100644 --- a/src/vs/editor/browser/standalone/simpleServices.ts +++ b/src/vs/editor/browser/standalone/simpleServices.ts @@ -55,7 +55,7 @@ export class SimpleEditor implements IEditor { public isVisible(): boolean { return true; } public withTypedEditor(codeEditorCallback: (editor: ICodeEditor) => T, diffEditorCallback: (editor: IDiffEditor) => T): T { - if (this._widget.getEditorType() === editorCommon.EditorType.ICodeEditor) { + if (editorCommon.isCommonCodeEditor(this._widget)) { // Single Editor return codeEditorCallback(this._widget); } else { diff --git a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts index be7fa17d0ac..85f713345ce 100644 --- a/src/vs/editor/browser/standalone/standaloneCodeEditor.ts +++ b/src/vs/editor/browser/standalone/standaloneCodeEditor.ts @@ -228,7 +228,7 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon oldModelUrl: null, newModelUrl: model.uri }; - this.emit(EventType.ModelChanged, e); + this._eventEmitter.emit(EventType.ModelChanged, e); } } diff --git a/src/vs/editor/browser/view/viewOutgoingEvents.ts b/src/vs/editor/browser/view/viewOutgoingEvents.ts index 1c47a209f25..2fb27ad7999 100644 --- a/src/vs/editor/browser/view/viewOutgoingEvents.ts +++ b/src/vs/editor/browser/view/viewOutgoingEvents.ts @@ -35,7 +35,7 @@ export class ViewOutgoingEvents extends Disposable { } public emitScrollChanged(e: viewEvents.ViewScrollChangedEvent): void { - this._actual.emit('scroll', e); + this._actual.emit(EventType.EditorScroll, e); } public emitViewFocusGained(): void { diff --git a/src/vs/editor/browser/widget/codeEditorWidget.ts b/src/vs/editor/browser/widget/codeEditorWidget.ts index 04b75215aab..343158e0859 100644 --- a/src/vs/editor/browser/widget/codeEditorWidget.ts +++ b/src/vs/editor/browser/widget/codeEditorWidget.ts @@ -33,17 +33,18 @@ import { InternalEditorAction } from 'vs/editor/common/editorAction'; export abstract class CodeEditorWidget extends CommonCodeEditor implements editorBrowser.ICodeEditor { - public readonly onMouseUp: Event = fromEventEmitter(this, editorCommon.EventType.MouseUp); - public readonly onMouseDown: Event = fromEventEmitter(this, editorCommon.EventType.MouseDown); - public readonly onMouseDrag: Event = fromEventEmitter(this, editorCommon.EventType.MouseDrag); - public readonly onMouseDrop: Event = fromEventEmitter(this, editorCommon.EventType.MouseDrop); - public readonly onContextMenu: Event = fromEventEmitter(this, editorCommon.EventType.ContextMenu); - public readonly onMouseMove: Event = fromEventEmitter(this, editorCommon.EventType.MouseMove); - public readonly onMouseLeave: Event = fromEventEmitter(this, editorCommon.EventType.MouseLeave); - public readonly onKeyUp: Event = fromEventEmitter(this, editorCommon.EventType.KeyUp); - public readonly onKeyDown: Event = fromEventEmitter(this, editorCommon.EventType.KeyDown); - public readonly onDidLayoutChange: Event = fromEventEmitter(this, editorCommon.EventType.EditorLayout); - public readonly onDidScrollChange: Event = fromEventEmitter(this, 'scroll'); + public readonly onMouseUp: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseUp); + public readonly onMouseDown: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseDown); + public readonly onMouseDrag: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseDrag); + public readonly onMouseDrop: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseDrop); + public readonly onContextMenu: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ContextMenu); + public readonly onMouseMove: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseMove); + public readonly onMouseLeave: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.MouseLeave); + public readonly onKeyUp: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.KeyUp); + public readonly onKeyDown: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.KeyDown); + public readonly onDidLayoutChange: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorLayout); + public readonly onDidScrollChange: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorScroll); + public readonly onDidChangeViewZones: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ViewZonesChanged); private _codeEditorService: ICodeEditorService; private _commandService: ICommandService; @@ -75,9 +76,9 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito let hasFocus = this._focusTracker.hasFocus(); if (hasFocus) { - this.emit(editorCommon.EventType.EditorFocus, {}); + this._eventEmitter.emit(editorCommon.EventType.EditorFocus, {}); } else { - this.emit(editorCommon.EventType.EditorBlur, {}); + this._eventEmitter.emit(editorCommon.EventType.EditorBlur, {}); } }); @@ -399,7 +400,7 @@ export abstract class CodeEditorWidget extends CommonCodeEditor implements edito } let hasChanges = this._view.change(callback); if (hasChanges) { - this.emit(editorCommon.EventType.ViewZonesChanged); + this._eventEmitter.emit(editorCommon.EventType.ViewZonesChanged); } } diff --git a/src/vs/editor/browser/widget/diffEditorWidget.ts b/src/vs/editor/browser/widget/diffEditorWidget.ts index af3e391a018..b7ece8a5387 100644 --- a/src/vs/editor/browser/widget/diffEditorWidget.ts +++ b/src/vs/editor/browser/widget/diffEditorWidget.ts @@ -7,7 +7,7 @@ import 'vs/css!./media/diffEditor'; import { RunOnceScheduler } from 'vs/base/common/async'; -import { EventEmitter, EmitterEvent } from 'vs/base/common/eventEmitter'; +import { EventEmitter } from 'vs/base/common/eventEmitter'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import * as objects from 'vs/base/common/objects'; import * as dom from 'vs/base/browser/dom'; @@ -376,13 +376,71 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif private _createLeftHandSideEditor(options: editorCommon.IDiffEditorOptions, instantiationService: IInstantiationService): void { this.originalEditor = this._createInnerEditor(instantiationService, this._originalDomNode, this._adjustOptionsForLeftHandSide(options, this._originalIsEditable)); - this._toDispose.push(this.originalEditor.addBulkListener((events) => this._onOriginalEditorEvents(events))); + + this._toDispose.push(this.originalEditor.onDidScrollChange((e) => { + if (this._isHandlingScrollEvent) { + return; + } + if (!e.scrollTopChanged && !e.scrollLeftChanged) { + return; + } + this._isHandlingScrollEvent = true; + this.modifiedEditor.setScrollPosition({ + scrollLeft: e.scrollLeft, + scrollTop: e.scrollTop + }); + this._isHandlingScrollEvent = false; + })); + + this._toDispose.push(this.originalEditor.onDidChangeViewZones(() => { + this._onViewZonesChanged(); + })); + + this._toDispose.push(this.originalEditor.onDidChangeModelContent(() => { + if (this._isVisible) { + this._beginUpdateDecorationsSoon(); + } + })); + this._toDispose.push(this.addEmitter(this.originalEditor)); } private _createRightHandSideEditor(options: editorCommon.IDiffEditorOptions, instantiationService: IInstantiationService): void { this.modifiedEditor = this._createInnerEditor(instantiationService, this._modifiedDomNode, this._adjustOptionsForRightHandSide(options)); - this._toDispose.push(this.modifiedEditor.addBulkListener((events) => this._onModifiedEditorEvents(events))); + + this._toDispose.push(this.modifiedEditor.onDidScrollChange((e) => { + if (this._isHandlingScrollEvent) { + return; + } + if (!e.scrollTopChanged && !e.scrollLeftChanged) { + return; + } + this._isHandlingScrollEvent = true; + this.originalEditor.setScrollPosition({ + scrollLeft: e.scrollLeft, + scrollTop: e.scrollTop + }); + this._isHandlingScrollEvent = false; + + this._layoutOverviewViewport(); + })); + + this._toDispose.push(this.modifiedEditor.onDidChangeViewZones(() => { + this._onViewZonesChanged(); + })); + + this._toDispose.push(this.modifiedEditor.onDidChangeConfiguration((e) => { + if (e.fontInfo && this.modifiedEditor.getModel()) { + this._onViewZonesChanged(); + } + })); + + this._toDispose.push(this.modifiedEditor.onDidChangeModelContent(() => { + if (this._isVisible) { + this._beginUpdateDecorationsSoon(); + } + })); + this._toDispose.push(this.addEmitter(this.modifiedEditor)); } @@ -747,62 +805,6 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif //------------ end layouting methods - private _recomputeIfNecessary(events: EmitterEvent[]): void { - let changed = false; - for (let i = 0; !changed && i < events.length; i++) { - let type = events[i].type; - changed = changed || type === editorCommon.EventType.ModelRawContentChanged2; - } - if (changed && this._isVisible) { - // Clear previous timeout if necessary - if (this._beginUpdateDecorationsTimeout !== -1) { - window.clearTimeout(this._beginUpdateDecorationsTimeout); - this._beginUpdateDecorationsTimeout = -1; - } - this._beginUpdateDecorationsTimeout = window.setTimeout(() => this._beginUpdateDecorations(), DiffEditorWidget.UPDATE_DIFF_DECORATIONS_DELAY); - } - } - - private _onOriginalEditorEvents(events: EmitterEvent[]): void { - for (let i = 0; i < events.length; i++) { - let type = events[i].type; - let data = events[i].data; - - if (type === 'scroll') { - this._onOriginalEditorScroll(data); - } - if (type === editorCommon.EventType.ViewZonesChanged) { - this._onViewZonesChanged(); - } - } - this._recomputeIfNecessary(events); - } - - private _onModifiedEditorEvents(events: EmitterEvent[]): void { - for (let i = 0; i < events.length; i++) { - let type = events[i].type; - let data = events[i].data; - - if (type === 'scroll') { - this._onModifiedEditorScroll(data); - this._layoutOverviewViewport(); - } - if (type === 'viewLayoutChanged') { - this._layoutOverviewViewport(); - } - if (type === editorCommon.EventType.ViewZonesChanged) { - this._onViewZonesChanged(); - } - if (type === editorCommon.EventType.ConfigurationChanged) { - let e = data; - if (e.fontInfo && this.modifiedEditor.getModel()) { - this._onViewZonesChanged(); - } - } - } - this._recomputeIfNecessary(events); - } - private _onViewZonesChanged(): void { if (this._currentlyChangingViewZones) { return; @@ -810,6 +812,15 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif this._updateDecorationsRunner.schedule(); } + private _beginUpdateDecorationsSoon(): void { + // Clear previous timeout if necessary + if (this._beginUpdateDecorationsTimeout !== -1) { + window.clearTimeout(this._beginUpdateDecorationsTimeout); + this._beginUpdateDecorationsTimeout = -1; + } + this._beginUpdateDecorationsTimeout = window.setTimeout(() => this._beginUpdateDecorations(), DiffEditorWidget.UPDATE_DIFF_DECORATIONS_DELAY); + } + private _beginUpdateDecorations(): void { this._beginUpdateDecorationsTimeout = -1; if (!this.modifiedEditor.getModel()) { @@ -904,36 +915,6 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif return result; } - private _onOriginalEditorScroll(e: editorCommon.IScrollEvent): void { - if (!e.scrollTopChanged && !e.scrollLeftChanged) { - return; - } - if (this._isHandlingScrollEvent) { - return; - } - this._isHandlingScrollEvent = true; - this.modifiedEditor.setScrollPosition({ - scrollLeft: e.scrollLeft, - scrollTop: e.scrollTop - }); - this._isHandlingScrollEvent = false; - } - - private _onModifiedEditorScroll(e: editorCommon.IScrollEvent): void { - if (!e.scrollTopChanged && !e.scrollLeftChanged) { - return; - } - if (this._isHandlingScrollEvent) { - return; - } - this._isHandlingScrollEvent = true; - this.originalEditor.setScrollPosition({ - scrollLeft: e.scrollLeft, - scrollTop: e.scrollTop - }); - this._isHandlingScrollEvent = false; - } - private _doLayout(): void { let splitPoint = this._strategy.layout(); diff --git a/src/vs/editor/common/commonCodeEditor.ts b/src/vs/editor/common/commonCodeEditor.ts index bab3fc9a5e1..c0e82aa69fc 100644 --- a/src/vs/editor/common/commonCodeEditor.ts +++ b/src/vs/editor/common/commonCodeEditor.ts @@ -6,7 +6,7 @@ import { onUnexpectedError } from 'vs/base/common/errors'; import Event, { fromEventEmitter } from 'vs/base/common/event'; -import { EventEmitter, IEventEmitter } from 'vs/base/common/eventEmitter'; +import { EventEmitter, IEventEmitter, BulkListenerCallback } from 'vs/base/common/eventEmitter'; import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { TPromise } from 'vs/base/common/winjs.base'; import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -32,24 +32,30 @@ import EditorContextKeys = editorCommon.EditorContextKeys; let EDITOR_ID = 0; -export abstract class CommonCodeEditor extends EventEmitter implements editorCommon.ICommonCodeEditor { +export abstract class CommonCodeEditor implements editorCommon.ICommonCodeEditor { - public readonly onDidChangeModelContent: Event = fromEventEmitter(this, editorCommon.EventType.ModelContentChanged); - public readonly onDidChangeModelLanguage: Event = fromEventEmitter(this, editorCommon.EventType.ModelLanguageChanged); - public readonly onDidChangeModelOptions: Event = fromEventEmitter(this, editorCommon.EventType.ModelOptionsChanged); - public readonly onDidChangeModelDecorations: Event = fromEventEmitter(this, editorCommon.EventType.ModelDecorationsChanged); - public readonly onDidChangeConfiguration: Event = fromEventEmitter(this, editorCommon.EventType.ConfigurationChanged); - public readonly onDidChangeModel: Event = fromEventEmitter(this, editorCommon.EventType.ModelChanged); - public readonly onDidChangeCursorPosition: Event = fromEventEmitter(this, editorCommon.EventType.CursorPositionChanged); - public readonly onDidChangeCursorSelection: Event = fromEventEmitter(this, editorCommon.EventType.CursorSelectionChanged); - public readonly onDidFocusEditorText: Event = fromEventEmitter(this, editorCommon.EventType.EditorTextFocus); - public readonly onDidBlurEditorText: Event = fromEventEmitter(this, editorCommon.EventType.EditorTextBlur); - public readonly onDidFocusEditor: Event = fromEventEmitter(this, editorCommon.EventType.EditorFocus); - public readonly onDidBlurEditor: Event = fromEventEmitter(this, editorCommon.EventType.EditorBlur); - public readonly onDidDispose: Event = fromEventEmitter(this, editorCommon.EventType.Disposed); - public readonly onWillType: Event = fromEventEmitter(this, editorCommon.EventType.WillType); - public readonly onDidType: Event = fromEventEmitter(this, editorCommon.EventType.DidType); - public readonly onDidPaste: Event = fromEventEmitter(this, editorCommon.EventType.DidPaste); + protected readonly _eventEmitter = new EventEmitter(); + + public readonly onDidChangeModelContent: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ModelContentChanged); + public readonly onDidChangeModelLanguage: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ModelLanguageChanged); + public readonly onDidChangeModelOptions: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ModelOptionsChanged); + public readonly onDidChangeModelDecorations: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ModelDecorationsChanged); + public readonly onDidChangeConfiguration: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ConfigurationChanged); + public readonly onDidChangeModel: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.ModelChanged); + public readonly onDidChangeCursorPosition: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.CursorPositionChanged); + public readonly onDidChangeCursorSelection: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.CursorSelectionChanged); + public readonly onDidFocusEditorText: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorTextFocus); + public readonly onDidBlurEditorText: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorTextBlur); + public readonly onDidFocusEditor: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorFocus); + public readonly onDidBlurEditor: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.EditorBlur); + public readonly onDidDispose: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.Disposed); + public readonly onWillType: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.WillType); + public readonly onDidType: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.DidType); + public readonly onDidPaste: Event = fromEventEmitter(this._eventEmitter, editorCommon.EventType.DidPaste); + + public addBulkListener(listener: BulkListenerCallback): IDisposable { + return this._eventEmitter.addBulkListener(listener); + } protected domElement: IContextKeyServiceTarget; @@ -85,8 +91,6 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom instantiationService: IInstantiationService, contextKeyService: IContextKeyService ) { - super(); - this.domElement = domElement; this.id = (++EDITOR_ID); @@ -105,10 +109,10 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom this._configuration = this._createConfiguration(options); this._lifetimeDispose.push(this._configuration.onDidChange((e) => { - this.emit(editorCommon.EventType.ConfigurationChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ConfigurationChanged, e); if (e.layoutInfo) { - this.emit(editorCommon.EventType.EditorLayout, this._configuration.editor.layoutInfo); + this._eventEmitter.emit(editorCommon.EventType.EditorLayout, this._configuration.editor.layoutInfo); } })); @@ -154,8 +158,8 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom this._postDetachModelCleanup(this._detachModel()); this._configuration.dispose(); this._contextKeyService.dispose(); - this.emit(editorCommon.EventType.Disposed); - super.dispose(); + this._eventEmitter.emit(editorCommon.EventType.Disposed); + this._eventEmitter.dispose(); } public captureState(...flags: editorCommon.CodeEditorStateFlag[]): editorCommon.ICodeEditorState { @@ -216,7 +220,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom newModelUrl: model ? model.uri : null }; - this.emit(editorCommon.EventType.ModelChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ModelChanged, e); this._postDetachModelCleanup(detachedModel); } @@ -553,11 +557,11 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom return; } if (source === 'keyboard') { - this.emit(editorCommon.EventType.WillType, payload.text); + this._eventEmitter.emit(editorCommon.EventType.WillType, payload.text); } this.cursor.trigger(source, handlerId, payload); if (source === 'keyboard') { - this.emit(editorCommon.EventType.DidType, payload.text); + this._eventEmitter.emit(editorCommon.EventType.DidType, payload.text); } return; } @@ -571,7 +575,7 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom this.cursor.trigger(source, handlerId, payload); const endPosition = this.cursor.getSelection().getStartPosition(); if (source === 'keyboard') { - this.emit(editorCommon.EventType.DidPaste, new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column)); + this._eventEmitter.emit(editorCommon.EventType.DidPaste, new Range(startPosition.lineNumber, startPosition.column, endPosition.lineNumber, endPosition.column)); } return; } @@ -772,24 +776,24 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom switch (eventType) { case editorCommon.EventType.ModelDecorationsChanged: - this.emit(editorCommon.EventType.ModelDecorationsChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ModelDecorationsChanged, e); break; case editorCommon.EventType.ModelLanguageChanged: this.domElement.setAttribute('data-mode-id', this.model.getLanguageIdentifier().language); - this.emit(editorCommon.EventType.ModelLanguageChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ModelLanguageChanged, e); break; case editorCommon.EventType.ModelRawContentChanged2: - this.emit(editorCommon.EventType.ModelRawContentChanged2, e); + this._eventEmitter.emit(editorCommon.EventType.ModelRawContentChanged2, e); break; case editorCommon.EventType.ModelContentChanged: - this.emit(editorCommon.EventType.ModelContentChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ModelContentChanged, e); break; case editorCommon.EventType.ModelOptionsChanged: - this.emit(editorCommon.EventType.ModelOptionsChanged, e); + this._eventEmitter.emit(editorCommon.EventType.ModelOptionsChanged, e); break; case editorCommon.EventType.ModelDispose: @@ -821,53 +825,53 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom switch (eventType) { case editorCommon.EventType.ViewFocusGained: - this.emit(editorCommon.EventType.EditorTextFocus); + this._eventEmitter.emit(editorCommon.EventType.EditorTextFocus); // In IE, the focus is not synchronous, so we give it a little help - this.emit(editorCommon.EventType.EditorFocus, {}); + this._eventEmitter.emit(editorCommon.EventType.EditorFocus, {}); break; - case 'scroll': - this.emit('scroll', e); + case editorCommon.EventType.EditorScroll: + this._eventEmitter.emit(editorCommon.EventType.EditorScroll, e); break; case editorCommon.EventType.ViewFocusLost: - this.emit(editorCommon.EventType.EditorTextBlur); + this._eventEmitter.emit(editorCommon.EventType.EditorTextBlur); break; case editorCommon.EventType.ContextMenu: - this.emit(editorCommon.EventType.ContextMenu, e); + this._eventEmitter.emit(editorCommon.EventType.ContextMenu, e); break; case editorCommon.EventType.MouseDown: - this.emit(editorCommon.EventType.MouseDown, e); + this._eventEmitter.emit(editorCommon.EventType.MouseDown, e); break; case editorCommon.EventType.MouseUp: - this.emit(editorCommon.EventType.MouseUp, e); + this._eventEmitter.emit(editorCommon.EventType.MouseUp, e); break; case editorCommon.EventType.MouseDrag: - this.emit(editorCommon.EventType.MouseDrag, e); + this._eventEmitter.emit(editorCommon.EventType.MouseDrag, e); break; case editorCommon.EventType.MouseDrop: - this.emit(editorCommon.EventType.MouseDrop, e); + this._eventEmitter.emit(editorCommon.EventType.MouseDrop, e); break; case editorCommon.EventType.KeyUp: - this.emit(editorCommon.EventType.KeyUp, e); + this._eventEmitter.emit(editorCommon.EventType.KeyUp, e); break; case editorCommon.EventType.MouseMove: - this.emit(editorCommon.EventType.MouseMove, e); + this._eventEmitter.emit(editorCommon.EventType.MouseMove, e); break; case editorCommon.EventType.MouseLeave: - this.emit(editorCommon.EventType.MouseLeave, e); + this._eventEmitter.emit(editorCommon.EventType.MouseLeave, e); break; case editorCommon.EventType.KeyDown: - this.emit(editorCommon.EventType.KeyDown, e); + this._eventEmitter.emit(editorCommon.EventType.KeyDown, e); break; default: @@ -883,11 +887,11 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom switch (eventType) { case editorCommon.EventType.CursorPositionChanged: - this.emit(editorCommon.EventType.CursorPositionChanged, e); + this._eventEmitter.emit(editorCommon.EventType.CursorPositionChanged, e); break; case editorCommon.EventType.CursorSelectionChanged: - this.emit(editorCommon.EventType.CursorSelectionChanged, e); + this._eventEmitter.emit(editorCommon.EventType.CursorSelectionChanged, e); break; default: diff --git a/src/vs/editor/common/editorCommon.ts b/src/vs/editor/common/editorCommon.ts index ed52d8bf8ab..795f04551d8 100644 --- a/src/vs/editor/common/editorCommon.ts +++ b/src/vs/editor/common/editorCommon.ts @@ -3456,36 +3456,6 @@ export interface IEditorAction { * An editor. */ export interface IEditor { - /** - * An event emitted when the content of the current model has changed. - * @event - */ - onDidChangeModelContent(listener: (e: IModelContentChangedEvent) => void): IDisposable; - /** - * An event emitted when the language of the current model has changed. - * @event - */ - onDidChangeModelLanguage(listener: (e: IModelLanguageChangedEvent) => void): IDisposable; - /** - * An event emitted when the options of the current model has changed. - * @event - */ - onDidChangeModelOptions(listener: (e: IModelOptionsChangedEvent) => void): IDisposable; - /** - * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) - * @event - */ - onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; - /** - * An event emitted when the cursor position has changed. - * @event - */ - onDidChangeCursorPosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable; - /** - * An event emitted when the cursor selection has changed. - * @event - */ - onDidChangeCursorSelection(listener: (e: ICursorSelectionChangedEvent) => void): IDisposable; /** * An event emitted when the editor has been disposed. * @event @@ -3845,6 +3815,36 @@ export interface IDecorationOptions { export interface ICommonCodeEditor extends IEditor { + /** + * An event emitted when the content of the current model has changed. + * @event + */ + onDidChangeModelContent(listener: (e: IModelContentChangedEvent) => void): IDisposable; + /** + * An event emitted when the language of the current model has changed. + * @event + */ + onDidChangeModelLanguage(listener: (e: IModelLanguageChangedEvent) => void): IDisposable; + /** + * An event emitted when the options of the current model has changed. + * @event + */ + onDidChangeModelOptions(listener: (e: IModelOptionsChangedEvent) => void): IDisposable; + /** + * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) + * @event + */ + onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; + /** + * An event emitted when the cursor position has changed. + * @event + */ + onDidChangeCursorPosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable; + /** + * An event emitted when the cursor selection has changed. + * @event + */ + onDidChangeCursorSelection(listener: (e: ICursorSelectionChangedEvent) => void): IDisposable; /** * An event emitted when the model of this editor has changed (e.g. `editor.setModel()`). * @event @@ -4163,6 +4163,7 @@ export var EventType = { ModelContentChanged: 'contentChanged', ModelRawContentChanged2: 'rawContentChanged2', + EditorScroll: 'scroll', EditorTextBlur: 'blur', EditorTextFocus: 'focus', EditorFocus: 'widgetFocus', diff --git a/src/vs/editor/contrib/codelens/browser/codelens.ts b/src/vs/editor/contrib/codelens/browser/codelens.ts index 89c9ea895fe..14929587abe 100644 --- a/src/vs/editor/contrib/codelens/browser/codelens.ts +++ b/src/vs/editor/contrib/codelens/browser/codelens.ts @@ -445,41 +445,31 @@ export class CodeLensContribution implements editorCommon.IEditorContribution { }, 250); this._localToDispose.push(scheduler); this._localToDispose.push(this._detectVisibleLenses); - this._localToDispose.push(model.addBulkListener((events) => { - let hadChange = false; - for (let i = 0; i < events.length; i++) { - const eventType = events[i].type; - if (eventType === editorCommon.EventType.ModelRawContentChanged2) { - hadChange = true; - break; - } - } - if (hadChange) { - this._editor.changeDecorations((changeAccessor) => { - this._editor.changeViewZones((viewAccessor) => { - const toDispose: CodeLens[] = []; - this._lenses.forEach((lens) => { - if (lens.isValid()) { - lens.update(viewAccessor); - } else { - toDispose.push(lens); - } - }); - - let helper = new CodeLensHelper(); - toDispose.forEach((l) => { - l.dispose(helper, viewAccessor); - this._lenses.splice(this._lenses.indexOf(l), 1); - }); - helper.commit(changeAccessor); + this._localToDispose.push(this._editor.onDidChangeModelContent((e) => { + this._editor.changeDecorations((changeAccessor) => { + this._editor.changeViewZones((viewAccessor) => { + const toDispose: CodeLens[] = []; + this._lenses.forEach((lens) => { + if (lens.isValid()) { + lens.update(viewAccessor); + } else { + toDispose.push(lens); + } }); - }); - // Compute new `visible` code lenses - this._detectVisibleLenses.schedule(); - // Ask for all references again - scheduler.schedule(); - } + let helper = new CodeLensHelper(); + toDispose.forEach((l) => { + l.dispose(helper, viewAccessor); + this._lenses.splice(this._lenses.indexOf(l), 1); + }); + helper.commit(changeAccessor); + }); + }); + + // Compute new `visible` code lenses + this._detectVisibleLenses.schedule(); + // Ask for all references again + scheduler.schedule(); })); this._localToDispose.push(this._editor.onDidScrollChange((e) => { if (e.scrollTopChanged) { diff --git a/src/vs/editor/contrib/quickOpen/browser/gotoLine.ts b/src/vs/editor/contrib/quickOpen/browser/gotoLine.ts index e0f2bbaebc2..c638e3248ed 100644 --- a/src/vs/editor/contrib/quickOpen/browser/gotoLine.ts +++ b/src/vs/editor/contrib/quickOpen/browser/gotoLine.ts @@ -51,20 +51,11 @@ export class GotoLineEntry extends QuickOpenEntry { position = { lineNumber: numbers[0], column: numbers[1] }; } - let editorType = (this.editor).getEditorType(), - model: editorCommon.IModel; - - switch (editorType) { - case editorCommon.EditorType.IDiffEditor: - model = (this.editor).getModel().modified; - break; - - case editorCommon.EditorType.ICodeEditor: - model = (this.editor).getModel(); - break; - - default: - throw new Error(); + let model: editorCommon.IModel; + if (editorCommon.isCommonCodeEditor(this.editor)) { + model = this.editor.getModel(); + } else { + model = (this.editor).getModel().modified; } let isValid = model.validatePosition(position).equals(position), diff --git a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts index 9a1aea6ca69..e81fd4456f5 100644 --- a/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts +++ b/src/vs/editor/contrib/referenceSearch/browser/referenceSearch.ts @@ -102,8 +102,8 @@ let findReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour return accessor.get(IEditorService).openEditor({ resource }).then(editor => { - let control = editor.getControl(); - if (!control || typeof control.getEditorType !== 'function') { + let control = editor.getControl(); + if (!editorCommon.isCommonCodeEditor(control)) { return undefined; } @@ -125,8 +125,8 @@ let showReferencesCommand: ICommandHandler = (accessor: ServicesAccessor, resour return accessor.get(IEditorService).openEditor({ resource: resource }).then(editor => { - let control = editor.getControl(); - if (!control || typeof control.getEditorType !== 'function') { + let control = editor.getControl(); + if (!editorCommon.isCommonCodeEditor(control)) { return undefined; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index d9f706b8f7e..29aa757d278 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -2971,36 +2971,6 @@ declare module monaco.editor { * An editor. */ export interface IEditor { - /** - * An event emitted when the content of the current model has changed. - * @event - */ - onDidChangeModelContent(listener: (e: IModelContentChangedEvent) => void): IDisposable; - /** - * An event emitted when the language of the current model has changed. - * @event - */ - onDidChangeModelLanguage(listener: (e: IModelLanguageChangedEvent) => void): IDisposable; - /** - * An event emitted when the options of the current model has changed. - * @event - */ - onDidChangeModelOptions(listener: (e: IModelOptionsChangedEvent) => void): IDisposable; - /** - * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) - * @event - */ - onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; - /** - * An event emitted when the cursor position has changed. - * @event - */ - onDidChangeCursorPosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable; - /** - * An event emitted when the cursor selection has changed. - * @event - */ - onDidChangeCursorSelection(listener: (e: ICursorSelectionChangedEvent) => void): IDisposable; /** * An event emitted when the editor has been disposed. * @event @@ -3195,6 +3165,36 @@ declare module monaco.editor { } export interface ICommonCodeEditor extends IEditor { + /** + * An event emitted when the content of the current model has changed. + * @event + */ + onDidChangeModelContent(listener: (e: IModelContentChangedEvent) => void): IDisposable; + /** + * An event emitted when the language of the current model has changed. + * @event + */ + onDidChangeModelLanguage(listener: (e: IModelLanguageChangedEvent) => void): IDisposable; + /** + * An event emitted when the options of the current model has changed. + * @event + */ + onDidChangeModelOptions(listener: (e: IModelOptionsChangedEvent) => void): IDisposable; + /** + * An event emitted when the configuration of the editor has changed. (e.g. `editor.updateOptions()`) + * @event + */ + onDidChangeConfiguration(listener: (e: IConfigurationChangedEvent) => void): IDisposable; + /** + * An event emitted when the cursor position has changed. + * @event + */ + onDidChangeCursorPosition(listener: (e: ICursorPositionChangedEvent) => void): IDisposable; + /** + * An event emitted when the cursor selection has changed. + * @event + */ + onDidChangeCursorSelection(listener: (e: ICursorSelectionChangedEvent) => void): IDisposable; /** * An event emitted when the model of this editor has changed (e.g. `editor.setModel()`). * @event diff --git a/src/vs/workbench/api/node/mainThreadWorkspace.ts b/src/vs/workbench/api/node/mainThreadWorkspace.ts index 78c536ee88f..a05c930f263 100644 --- a/src/vs/workbench/api/node/mainThreadWorkspace.ts +++ b/src/vs/workbench/api/node/mainThreadWorkspace.ts @@ -9,7 +9,7 @@ import { ISearchService, QueryType } from 'vs/platform/search/common/search'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; +import { ICommonCodeEditor, isCommonCodeEditor } from 'vs/editor/common/editorCommon'; import { bulkEdit, IResourceEdit } from 'vs/editor/common/services/bulkEdit'; import { TPromise } from 'vs/base/common/winjs.base'; import { Uri } from 'vscode'; @@ -94,9 +94,8 @@ export class MainThreadWorkspace extends MainThreadWorkspaceShape { let codeEditor: ICommonCodeEditor; let editor = this._editorService.getActiveEditor(); if (editor) { - let candidate = editor.getControl(); - if (typeof candidate.getEditorType === 'function') { - // enough proof + let candidate = editor.getControl(); + if (isCommonCodeEditor(candidate)) { codeEditor = candidate; } } diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 10dc48bd78f..88f12913ba4 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -24,8 +24,7 @@ import { IDisposable, combinedDisposable, dispose } from 'vs/base/common/lifecyc import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing'; -import { IEditorAction, ICommonCodeEditor, IModelOptionsChangedEvent, IModelLanguageChangedEvent, ICursorPositionChangedEvent, EndOfLineSequence, EditorType, IModel, IDiffEditorModel, IEditor } from 'vs/editor/common/editorCommon'; -import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; +import { IEditorAction, ICommonCodeEditor, IModelOptionsChangedEvent, IModelLanguageChangedEvent, ICursorPositionChangedEvent, EndOfLineSequence, IModel } from 'vs/editor/common/editorCommon'; import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/common/linesOperations'; import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/editor/contrib/indentation/common/indentation'; import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor'; @@ -47,26 +46,6 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile import { getCodeEditor as getEditorWidget } from 'vs/editor/common/services/codeEditorService'; import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences'; -function getCodeEditor(editorWidget: IEditor): ICommonCodeEditor { - if (editorWidget) { - if (editorWidget.getEditorType() === EditorType.IDiffEditor) { - return (editorWidget).getModifiedEditor(); - } - if (editorWidget.getEditorType() === EditorType.ICodeEditor) { - return (editorWidget); - } - } - return null; -} - -function getTextModel(editorWidget: IEditor): IModel { - - // make sure to resolve any possible diff editors to their modified side - editorWidget = getCodeEditor(editorWidget); - - return editorWidget ? editorWidget.getModel() : null; -} - function toEditorWithEncodingSupport(input: IEditorInput): IEncodingSupport { if (input instanceof SideBySideEditorInput) { input = input.master; @@ -477,7 +456,7 @@ export class EditorStatus implements IStatusbarItem { private onEditorsChanged(): void { const activeEditor = this.editorService.getActiveEditor(); - let control: IEditor = getEditorWidget(activeEditor); + const control = getEditorWidget(activeEditor); // Update all states this.onSelectionChange(control); @@ -539,12 +518,12 @@ export class EditorStatus implements IStatusbarItem { } } - private onModeChange(editorWidget?: IEditor): void { + private onModeChange(editorWidget: ICommonCodeEditor): void { let info: StateDelta = { mode: null }; // We only support text based editors if (editorWidget) { - const textModel = getTextModel(editorWidget); + const textModel = editorWidget.getModel(); if (textModel) { // Compute mode const modeId = textModel.getLanguageIdentifier().language; @@ -555,15 +534,11 @@ export class EditorStatus implements IStatusbarItem { this.updateState(info); } - private onIndentationChange(editorWidget?: IEditor): void { + private onIndentationChange(editorWidget: ICommonCodeEditor): void { const update: StateDelta = { indentation: null }; if (editorWidget) { - if (editorWidget.getEditorType() === EditorType.IDiffEditor) { - editorWidget = (editorWidget).getModifiedEditor(); - } - - const model = (editorWidget).getModel(); + const model = editorWidget.getModel(); if (model) { const modelOpts = model.getOptions(); update.indentation = ( @@ -587,7 +562,7 @@ export class EditorStatus implements IStatusbarItem { this.updateState(update); } - private onSelectionChange(editorWidget?: IEditor): void { + private onSelectionChange(editorWidget: ICommonCodeEditor): void { const info: IEditorSelectionStatus = {}; // We only support text based editors @@ -598,7 +573,7 @@ export class EditorStatus implements IStatusbarItem { // Compute selection length info.charactersSelected = 0; - const textModel = getTextModel(editorWidget); + const textModel = editorWidget.getModel(); if (textModel) { info.selections.forEach(selection => { info.charactersSelected += textModel.getValueLengthInRange(selection); @@ -624,12 +599,11 @@ export class EditorStatus implements IStatusbarItem { this.updateState({ selectionStatus: this.getSelectionLabel(info) }); } - private onEOLChange(editorWidget?: IEditor): void { + private onEOLChange(editorWidget: ICommonCodeEditor): void { const info: StateDelta = { EOL: null }; - const codeEditor = getCodeEditor(editorWidget); - if (codeEditor && !codeEditor.getConfiguration().readOnly) { - const codeEditorModel = codeEditor.getModel(); + if (editorWidget && !editorWidget.getConfiguration().readOnly) { + const codeEditorModel = editorWidget.getModel(); if (codeEditorModel) { info.EOL = codeEditorModel.getEOL(); } @@ -685,18 +659,16 @@ export class EditorStatus implements IStatusbarItem { } } -function isWritableCodeEditor(e: IBaseEditor): boolean { - let editorWidget: IEditor = getEditorWidget(e); - if (!editorWidget) { +function isWritableCodeEditor(codeEditor: ICommonCodeEditor): boolean { + if (!codeEditor) { return false; } + const config = codeEditor.getConfiguration(); + return (!config.readOnly); +} - if (editorWidget.getEditorType() === EditorType.IDiffEditor) { - editorWidget = (editorWidget).getModifiedEditor(); - } - - return (editorWidget.getEditorType() === EditorType.ICodeEditor && - !(editorWidget).getConfiguration().readOnly); +function isWritableBaseEditor(e: IBaseEditor): boolean { + return isWritableCodeEditor(getEditorWidget(e)); } export class ShowLanguageExtensionsAction extends Action { @@ -750,7 +722,7 @@ export class ChangeModeAction extends Action { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } - const textModel = getTextModel(editorWidget); + const textModel = editorWidget.getModel(); const fileResource = toResource(activeEditor.input, { supportSideBySide: true, filter: 'file' }); // Compute mode @@ -844,21 +816,15 @@ export class ChangeModeAction extends Action { // Change mode for active editor activeEditor = this.editorService.getActiveEditor(); - const editorWidget: IEditor = getEditorWidget(activeEditor); + const editorWidget = getEditorWidget(activeEditor); if (editorWidget) { const models: IModel[] = []; - const textModel = getTextModel(editorWidget); + const textModel = editorWidget.getModel(); if (textModel) { models.push(textModel); } - // Support for original side of diff - const model = editorWidget.getModel(); - if (model && !!(model).original) { - models.push((model).original); - } - // Find mode let mode: TPromise; if (pick === autoDetectMode) { @@ -949,7 +915,7 @@ class ChangeIndentationAction extends Action { if (!control) { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } - if (!isWritableCodeEditor(activeEditor)) { + if (!isWritableCodeEditor(control)) { return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]); } @@ -1000,11 +966,11 @@ export class ChangeEOLAction extends Action { return this.quickOpenService.pick([{ label: nls.localize('noEditor', "No text editor active at this time") }]); } - if (!isWritableCodeEditor(activeEditor)) { + if (!isWritableCodeEditor(editorWidget)) { return this.quickOpenService.pick([{ label: nls.localize('noWritableCodeEditor', "The active code editor is read-only.") }]); } - const textModel = getTextModel(editorWidget); + const textModel = editorWidget.getModel(); const EOLOptions: IChangeEOLEntry[] = [ { label: nlsEOLLF, eol: EndOfLineSequence.LF }, @@ -1017,8 +983,8 @@ export class ChangeEOLAction extends Action { if (eol) { activeEditor = this.editorService.getActiveEditor(); const editorWidget = getEditorWidget(activeEditor); - if (editorWidget && isWritableCodeEditor(activeEditor)) { - const textModel = getTextModel(editorWidget); + if (editorWidget && isWritableCodeEditor(editorWidget)) { + const textModel = editorWidget.getModel(); textModel.setEOL(eol.eol); } } @@ -1067,7 +1033,7 @@ export class ChangeEncodingAction extends Action { if (encodingSupport instanceof UntitledEditorInput) { pickActionPromise = TPromise.as(saveWithEncodingPick); - } else if (!isWritableCodeEditor(activeEditor)) { + } else if (!isWritableBaseEditor(activeEditor)) { pickActionPromise = TPromise.as(reopenWithEncodingPick); } else { pickActionPromise = this.quickOpenService.pick([reopenWithEncodingPick, saveWithEncodingPick], { placeHolder: nls.localize('pickAction', "Select Action"), matchOnDetail: true }); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts index 2dbedfa1234..16926ebfc58 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugConfigurationManager.ts @@ -12,7 +12,7 @@ import uri from 'vs/base/common/uri'; import { Schemas } from 'vs/base/common/network'; import * as paths from 'vs/base/common/paths'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; -import { IModel, ICommonCodeEditor, EditorType } from 'vs/editor/common/editorCommon'; +import { IModel, isCommonCodeEditor } from 'vs/editor/common/editorCommon'; import { IEditor } from 'vs/platform/editor/common/editor'; import * as extensionsRegistry from 'vs/platform/extensions/common/extensionsRegistry'; import { Registry } from 'vs/platform/platform'; @@ -398,8 +398,8 @@ export class ConfigurationManager implements debug.IConfigurationManager { const editor = this.editorService.getActiveEditor(); if (editor) { - const codeEditor = editor.getControl(); - if (codeEditor && codeEditor.getEditorType() === EditorType.ICodeEditor) { + const codeEditor = editor.getControl(); + if (isCommonCodeEditor(codeEditor)) { const model = codeEditor.getModel(); const language = model ? model.getLanguageIdentifier().language : undefined; const adapters = this.adapters.filter(a => a.languages && a.languages.indexOf(language) >= 0); diff --git a/src/vs/workbench/parts/git/browser/gitActions.contribution.ts b/src/vs/workbench/parts/git/browser/gitActions.contribution.ts index 51187b0deeb..308de1c9ee9 100644 --- a/src/vs/workbench/parts/git/browser/gitActions.contribution.ts +++ b/src/vs/workbench/parts/git/browser/gitActions.contribution.ts @@ -385,7 +385,7 @@ export abstract class BaseStageRangesAction extends baseeditor.EditorInputAction this.editorService = editorService; this.gitService = gitService; this.editor = editor.getControl(); - this.editor.onDidChangeCursorSelection(() => this.updateEnablement()); + this.editor.getModifiedEditor().onDidChangeCursorSelection(() => this.updateEnablement()); this.editor.onDidUpdateDiff(() => this.updateEnablement()); this.class = 'git-action stage-ranges'; } @@ -492,7 +492,7 @@ export class RevertRangesAction extends baseeditor.EditorInputAction { super(RevertRangesAction.ID, RevertRangesAction.LABEL); this.editor = editor.getControl(); - this.editor.onDidChangeCursorSelection(() => this.updateEnablement()); + this.editor.getModifiedEditor().onDidChangeCursorSelection(() => this.updateEnablement()); this.editor.onDidUpdateDiff(() => this.updateEnablement()); this.class = 'git-action revert-ranges'; } diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index a259e110d5d..65cc1a9a811 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -9,13 +9,12 @@ import 'vs/css!./media/searchviewlet'; import nls = require('vs/nls'); import { TPromise } from 'vs/base/common/winjs.base'; import { Emitter, debounceEvent } from 'vs/base/common/event'; -import { EditorType, ICommonCodeEditor } from 'vs/editor/common/editorCommon'; +import { ICommonCodeEditor, isCommonCodeEditor } from 'vs/editor/common/editorCommon'; import lifecycle = require('vs/base/common/lifecycle'); import errors = require('vs/base/common/errors'); import aria = require('vs/base/browser/ui/aria/aria'); import { IExpression } from 'vs/base/common/glob'; import env = require('vs/base/common/platform'); -import { isFunction } from 'vs/base/common/types'; import { Delayer } from 'vs/base/common/async'; import URI from 'vs/base/common/uri'; import strings = require('vs/base/common/strings'); @@ -803,7 +802,7 @@ export class SearchViewlet extends Viewlet { } let editorControl: any = this.editorService.getActiveEditor().getControl(); - if (!editorControl || !isFunction(editorControl.getEditorType) || editorControl.getEditorType() !== EditorType.ICodeEditor) { // Substitute for (editor instanceof ICodeEditor) + if (!isCommonCodeEditor(editorControl)) { return null; }