Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Sep 11, 2019
1 parent e500624 commit 6691758
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
17 changes: 0 additions & 17 deletions packages/java/scripts/.project

This file was deleted.

20 changes: 6 additions & 14 deletions packages/plugin-ext/src/main/browser/text-editor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
/**
Expand All @@ -38,15 +38,13 @@ export class TextEditorServiceImpl implements TextEditorService {
onTextEditorAdd: Event<MonacoEditor> = this.onTextEditorAddEmitter.event;
onTextEditorRemove: Event<MonacoEditor> = this.onTextEditorRemoveEmitter.event;

private editors = new Map<string, MonacoEditor>();

constructor(@inject(EditorManager) private editorManager: EditorManager) {
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 {
Expand All @@ -62,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);
}

}

0 comments on commit 6691758

Please sign in to comment.