1
1
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' ;
4
2
import { CommonCommands } from '@theia/core/lib/browser/common-frontend-contribution' ;
5
3
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service' ;
6
4
import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service' ;
5
+ import { MonacoEditorService } from '@theia/monaco/lib/browser/monaco-editor-service' ;
7
6
import { EDITOR_FONT_DEFAULTS } from '@theia/editor/lib/browser/editor-preferences' ;
8
7
import { Contribution , Command , MenuModelRegistry , KeybindingRegistry , CommandRegistry } from './contribution' ;
9
8
import { ArduinoMenus } from '../menu/arduino-menus' ;
@@ -13,8 +12,8 @@ import { ArduinoMenus } from '../menu/arduino-menus';
13
12
@injectable ( )
14
13
export class EditContributions extends Contribution {
15
14
16
- @inject ( EditorManager )
17
- protected readonly editorManager : EditorManager ;
15
+ @inject ( MonacoEditorService )
16
+ protected readonly codeEditorService : MonacoEditorService ;
18
17
19
18
@inject ( ClipboardService )
20
19
protected readonly clipboardService : ClipboardService ;
@@ -209,19 +208,19 @@ ${value}
209
208
} ) ;
210
209
}
211
210
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 ( ) ;
215
213
}
216
214
217
215
protected async currentValue ( ) : Promise < string | undefined > {
218
- return this . editorManager . currentEditor ?. editor . document . getText ( ) ;
216
+ const currentEditor = await this . current ( )
217
+ return currentEditor ?. getValue ( ) ;
219
218
}
220
219
221
220
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 ( ) ;
223
222
if ( editor ) {
224
- const action = editor . getControl ( ) . getAction ( commandId ) ;
223
+ const action = editor . getAction ( commandId ) ;
225
224
if ( action ) {
226
225
return action . run ( ) ;
227
226
}
0 commit comments