Skip to content

Commit

Permalink
feat: insert code
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Jul 29, 2022
1 parent cee3a64 commit 29230b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -16,7 +16,7 @@ export class ApiScriptComponent implements OnInit {
@Input() treeData = [];
@Input() completions = [];
@Output() codeChange: EventEmitter<any> = new EventEmitter();
@ViewChild(EoEditorComponent, { static: false }) eoEditor?: EoEditorComponent;
@ViewChild(EoMonacoEditorComponent, { static: false }) eoEditor?: EoMonacoEditorComponent;
@ViewChild('nzTreeComponent', { static: false }) nzTreeComponent!: NzTreeComponent;

selectListSelection = new SelectionModel<FlatNode>(true);
Expand Down Expand Up @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 29230b8

Please sign in to comment.