From 29230b8de15136db54769ce0e584dd58829e5232 Mon Sep 17 00:00:00 2001 From: buqiyuan <1743369777@qq.com> Date: Fri, 29 Jul 2022 18:31:42 +0800 Subject: [PATCH] feat: insert code --- .../components/api-script/api-script.component.ts | 6 +++--- .../monaco-editor/monaco-editor.component.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts index 5de9c8e0b..cdd68677b 100644 --- a/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts +++ b/src/workbench/browser/src/app/shared/components/api-script/api-script.component.ts @@ -1,6 +1,6 @@ import { SelectionModel } from '@angular/cdk/collections'; import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'; -import { EoEditorComponent } from 'eo/workbench/browser/src/app/eoui/editor/eo-editor/eo-editor.component'; +import { EoMonacoEditorComponent } from 'eo/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component'; import { NzFormatEmitEvent, NzTreeComponent, NzTreeNodeOptions } from 'ng-zorro-antd/tree'; @@ -16,7 +16,7 @@ export class ApiScriptComponent implements OnInit { @Input() treeData = []; @Input() completions = []; @Output() codeChange: EventEmitter = new EventEmitter(); - @ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent; + @ViewChild(EoMonacoEditorComponent, { static: false }) eoEditor?: EoMonacoEditorComponent; @ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent; selectListSelection = new SelectionModel(true); @@ -61,7 +61,7 @@ export class ApiScriptComponent implements OnInit { } insertCode = (event) => { - console.log('isertCode',event) + console.log('isertCode', event); const { value } = event.origin; this.eoEditor.handleInsert(value); }; diff --git a/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts b/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts index 7fc275e26..60e3baab7 100644 --- a/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts +++ b/src/workbench/browser/src/app/shared/components/monaco-editor/monaco-editor.component.ts @@ -244,7 +244,17 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges } } - handleInsert(code) {} + handleInsert(code) { + const p = this.codeEdtor.getPosition(); + this.codeEdtor.executeEdits('', [ + { + range: new monaco.Range(p.lineNumber, p.column, p.lineNumber, p.column), + text: code, + }, + ]); + this.codeEdtor.focus(); + // this.codeEdtor.trigger('keyboard', 'type', { text: code }); + } onEditorInitialized(codeEdtor) { this.codeEdtor = codeEdtor;