diff --git a/packages/plugin-ext/src/main/browser/text-editor-service.ts b/packages/plugin-ext/src/main/browser/text-editor-service.ts index dc6c4a419282a..edf7e35f6c56b 100644 --- a/packages/plugin-ext/src/main/browser/text-editor-service.ts +++ b/packages/plugin-ext/src/main/browser/text-editor-service.ts @@ -13,10 +13,10 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { Event, Emitter } from '@theia/core'; +import { Emitter, Event } from '@theia/core'; import { EditorManager, EditorWidget } from '@theia/editor/lib/browser'; -import { injectable, inject } from 'inversify'; import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor'; +import { inject, injectable } from 'inversify'; export const TextEditorService = Symbol('TextEditorService'); /** @@ -38,25 +38,19 @@ export class TextEditorServiceImpl implements TextEditorService { onTextEditorAdd: Event = this.onTextEditorAddEmitter.event; onTextEditorRemove: Event = this.onTextEditorRemoveEmitter.event; - private editors = new Map(); - constructor(@inject(EditorManager) private editorManager: EditorManager) { - editorManager.onCurrentEditorChanged(this.onEditorChanged); editorManager.onCreated(w => this.onEditorCreated(w)); + editorManager.all.forEach(w => this.onEditorCreated(w)); } listTextEditors(): MonacoEditor[] { - return Array.from(this.editors.values()); + return this.editorManager.all.map(w => MonacoEditor.get(w)!).filter(editor => editor !== undefined); } getActiveEditor(): EditorWidget | undefined { return this.editorManager.activeEditor; } - private onEditorChanged(editor: EditorWidget | undefined): void { - // console.log(`Current Editor Changed: ${editor}`); - } - private onEditorCreated(editor: EditorWidget): void { const monacoEditor = MonacoEditor.get(editor); if (monacoEditor) { @@ -66,16 +60,10 @@ export class TextEditorServiceImpl implements TextEditorService { } private onEditorAdded(editor: MonacoEditor): void { - if (!this.editors.has(editor.getControl().getId())) { - this.editors.set(editor.getControl().getId(), editor); - this.onTextEditorAddEmitter.fire(editor); - } + this.onTextEditorAddEmitter.fire(editor); } + private onEditorRemoved(editor: MonacoEditor): void { - if (this.editors.has(editor.getControl().getId())) { - this.editors.delete(editor.getControl().getId()); - this.onTextEditorRemoveEmitter.fire(editor); - } + this.onTextEditorRemoveEmitter.fire(editor); } - }