Skip to content

Commit

Permalink
Set active editor on startup
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 12, 2019
1 parent 4103e56 commit 393efba
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 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,25 +38,19 @@ 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.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) {
Expand All @@ -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);
}

}

0 comments on commit 393efba

Please sign in to comment.