Skip to content

Commit 491e0cb

Browse files
author
Akos Kitta
committed
fixed the current editor issue.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent e95f004 commit 491e0cb

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

arduino-ide-extension/src/browser/contributions/edit-contributions.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { inject, injectable } from 'inversify';
2-
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
3-
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
42
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution';
53
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
64
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service';
5+
import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service';
76
import { EDITOR_FONT_DEFAULTS } from '@theia/editor/lib/browser/editor-preferences';
87
import { Contribution, Command, MenuModelRegistry, KeybindingRegistry, CommandRegistry } from './contribution';
98
import { ArduinoMenus } from '../menu/arduino-menus';
@@ -13,8 +12,8 @@ import { ArduinoMenus } from '../menu/arduino-menus';
1312
@injectable()
1413
export class EditContributions extends Contribution {
1514

16-
@inject(EditorManager)
17-
protected readonly editorManager: EditorManager;
15+
@inject(MonacoEditorService)
16+
protected readonly codeEditorService: MonacoEditorService;
1817

1918
@inject(ClipboardService)
2019
protected readonly clipboardService: ClipboardService;
@@ -209,19 +208,19 @@ ${value}
209208
});
210209
}
211210

212-
protected async current(): Promise<MonacoEditor | undefined> {
213-
const editor = this.editorManager.currentEditor?.editor;
214-
return editor instanceof MonacoEditor ? editor : undefined;
211+
protected async current(): Promise<monaco.editor.ICodeEditor | undefined> {
212+
return this.codeEditorService.getFocusedCodeEditor() || this.codeEditorService.getActiveCodeEditor();
215213
}
216214

217215
protected async currentValue(): Promise<string | undefined> {
218-
return this.editorManager.currentEditor?.editor.document.getText();
216+
const currentEditor = await this.current()
217+
return currentEditor?.getValue();
219218
}
220219

221220
protected async run(commandId: string): Promise<any> {
222-
const editor = await this.current(); // TODO: this should be the active monaco editor and not Theia editor. e.g: Output
221+
const editor = await this.current();
223222
if (editor) {
224-
const action = editor.getControl().getAction(commandId);
223+
const action = editor.getAction(commandId);
225224
if (action) {
226225
return action.run();
227226
}

0 commit comments

Comments
 (0)