How to use the @theia/monaco/lib/browser/monaco-editor.MonacoEditor.get function in @theia/monaco

To help you get started, we’ve selected a few @theia/monaco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / editorconfig / src / browser / editorconfig-document-manager.ts View on Github external
protected addOnSaveHandler(editorWidget: EditorWidget): void {
        const monacoEditor = MonacoEditor.get(editorWidget);
        if (monacoEditor) {
            monacoEditor.document.onWillSaveModel(event => {
                event.waitUntil(new Promise(resolve => {
                    const uri = monacoEditor.uri.toString();
                    const properties = this.properties[uri];

                    const edits = [];
                    edits.push(...this.getEditsTrimmingTrailingWhitespaces(monacoEditor, properties, event.reason));

                    const edit = this.getEditInsertingFinalNewLine(monacoEditor, properties);
                    if (edit) {
                        edits.push(edit);

                        // get current cursor position
                        const cursor = monacoEditor.cursor;
github eclipse-theia / theia / packages / typescript / src / browser / typescript-frontend-contribution.ts View on Github external
organizeImports(): void {
        const editor = MonacoEditor.get(this.currentEditor);
        if (editor) {
            // tslint:disable-next-line:no-any
            const action = editor.getControl().getAction('editor.action.organizeImports') as any;
            // workaround isSupported check
            action._run();
        }
    }
github eclipse-theia / theia / packages / editorconfig / src / browser / editorconfig-document-manager.ts View on Github external
private getEditsTrimmingTrailingWhitespaces(editor: MonacoEditor, properties: KnownProps, saveReason?: TextDocumentSaveReason): monaco.editor.IIdentifiedSingleEditOperation[] {
        const edits = [];

        if (this.isSet(properties.trim_trailing_whitespace)) {
            if (MonacoEditor.get(this.editorManager.activeEditor) === editor) {
                const trimReason = (saveReason !== TextDocumentSaveReason.Manual) ? 'auto-save' : undefined;
                editor.commandService.executeCommand('editor.action.trimTrailingWhitespace', {
                    reason: trimReason
                });
                return [];
            }

            const lines = editor.document.lineCount;
            for (let i = 1; i <= lines; i++) {
                const line = editor.document.textEditorModel.getLineContent(i);
                const trimmedLine = line.trimRight();

                if (line.length !== trimmedLine.length) {
                    edits.push({
                        forceMoveMarkers: false,
                        range: new monaco.Range(i, trimmedLine.length + 1, i, line.length + 1),
github eclipse-theia / theia / packages / plugin-ext / src / main / browser / text-editor-service.ts View on Github external
private onEditorCreated(editor: EditorWidget): void {
        const monacoEditor = MonacoEditor.get(editor);
        if (monacoEditor) {
            this.onEditorAdded(monacoEditor);
            editor.disposed.connect(e => this.onEditorRemoved(monacoEditor));
        }
    }