From 491e0cb6d03b979d1de76dbc4e64abe06ed499a2 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Wed, 22 Jul 2020 12:06:33 +0200 Subject: [PATCH] fixed the current editor issue. Signed-off-by: Akos Kitta --- .../contributions/edit-contributions.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts index 957bd8aa..7d551e19 100644 --- a/arduino-ide-extension/src/browser/contributions/edit-contributions.ts +++ b/arduino-ide-extension/src/browser/contributions/edit-contributions.ts @@ -1,9 +1,8 @@ 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 { ClipboardService } from '@theia/core/lib/browser/clipboard-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 { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution'; import { ArduinoMenus } from '../menu/arduino-menus'; @@ -13,8 +12,8 @@ import { ArduinoMenus } from '../menu/arduino-menus'; @injectable() export class EditContributions extends Contribution { - @inject(EditorManager) - protected readonly editorManager: EditorManager; + @inject(MonacoEditorService) + protected readonly codeEditorService: MonacoEditorService; @inject(ClipboardService) protected readonly clipboardService: ClipboardService; @@ -209,19 +208,19 @@ ${value} }); } - protected async current(): Promise { - const editor = this.editorManager.currentEditor?.editor; - return editor instanceof MonacoEditor ? editor : undefined; + protected async current(): Promise { + return this.codeEditorService.getFocusedCodeEditor() || this.codeEditorService.getActiveCodeEditor(); } protected async currentValue(): Promise { - return this.editorManager.currentEditor?.editor.document.getText(); + const currentEditor = await this.current() + return currentEditor?.getValue(); } protected async run(commandId: string): Promise { - 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) { - const action = editor.getControl().getAction(commandId); + const action = editor.getAction(commandId); if (action) { return action.run(); }