fixed the current editor issue.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta 2020-07-22 12:06:33 +02:00
parent e95f00466f
commit 491e0cb6d0

View File

@ -1,9 +1,8 @@
import { inject, injectable } from 'inversify'; import { inject, injectable } from 'inversify';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution'; import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service'; import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service'; import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
import { EDITOR_FONT_DEFAULTS } from '@theia/editor/lib/browser/editor-preferences'; import { EDITOR_FONT_DEFAULTS } from '@theia/editor/lib/browser/editor-preferences';
import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution'; import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
import { ArduinoMenus } from '../menu/arduino-menus'; import { ArduinoMenus } from '../menu/arduino-menus';
@ -13,8 +12,8 @@ import { ArduinoMenus } from '../menu/arduino-menus';
@injectable() @injectable()
export class EditContributions extends Contribution { export class EditContributions extends Contribution {
@inject(EditorManager) @inject(MonacoEditorService)
protected readonly editorManager: EditorManager; protected readonly codeEditorService: MonacoEditorService;
@inject(ClipboardService) @inject(ClipboardService)
protected readonly clipboardService: ClipboardService; protected readonly clipboardService: ClipboardService;
@ -209,19 +208,19 @@ ${value}
}); });
} }
protected async current(): Promise<MonacoEditor | undefined> { protected async current(): Promise<monaco.editor.ICodeEditor | undefined> {
const editor = this.editorManager.currentEditor?.editor; return this.codeEditorService.getFocusedCodeEditor() || this.codeEditorService.getActiveCodeEditor();
return editor instanceof MonacoEditor ? editor : undefined;
} }
protected async currentValue(): Promise<string | undefined> { protected async currentValue(): Promise<string | undefined> {
return this.editorManager.currentEditor?.editor.document.getText(); const currentEditor = await this.current()
return currentEditor?.getValue();
} }
protected async run(commandId: string): Promise<any> { protected async run(commandId: string): Promise<any> {
const editor = await this.current(); // TODO: this should be the active monaco editor and not Theia editor. e.g: Output const editor = await this.current();
if (editor) { if (editor) {
const action = editor.getControl().getAction(commandId); const action = editor.getAction(commandId);
if (action) { if (action) {
return action.run(); return action.run();
} }