Skip to content

Commit

Permalink
fix: make code be string
Browse files Browse the repository at this point in the history
  • Loading branch information
buqiyuan committed Jul 31, 2022
1 parent ce625e2 commit b825cae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
<span>{{ item.label }}</span>
</div>
</div>
<nz-code-editor [(ngModel)]="code" style="min-height: 100px;" [nzEditorOption]="editorOption"
<nz-code-editor [(ngModel)]="$$code" style="min-height: 100px;" [nzEditorOption]="editorOption"
(nzEditorInitialized)="onEditorInitialized($event)"></nz-code-editor>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ const eventHash = new Map()
export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges, OnDestroy {
@Input() eventList: EventType[] = [];
@Input() hiddenList: string[] = [];
@Input() code: string;
@Input() set code(val) {
if (val === this.$$code) {
return;
}
try {
this.$$code = JSON.stringify(val);
} catch {
this.$$code = String(val);
}
}
/** Scroll bars appear over 20 lines */
@Input() maxLine = 200;
@Input() config: JoinedEditorOptions = {};
Expand All @@ -43,6 +52,7 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges
@Input() disabled = false;
@Input() completions = [];
@Output() codeChange = new EventEmitter<string>();
$$code = '';
codeEdtor: editor.IStandaloneCodeEditor;
isReadOnly = false;
completionItemProvider: monaco.IDisposable;
Expand Down Expand Up @@ -95,10 +105,10 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges
ngOnChanges() {
// * update root type
if (this.eventList.includes('type') && !this.hiddenList.includes('type')) {
const type = whatTextType(this.code || '');
const type = whatTextType(this.$$code || '');
this.editorType = type;
if (this.autoFormat) {
this.code = this.formatCode();
this.$$code = this.formatCode();
}
}
}
Expand Down Expand Up @@ -188,10 +198,10 @@ export class EoMonacoEditorComponent implements AfterViewInit, OnInit, OnChanges
console.log('ace event', event, txt);
}
handleBlur() {
this.codeChange.emit(this.code);
this.codeChange.emit(this.$$code);
}
handleChange() {
this.codeChange.emit(this.code);
this.codeChange.emit(this.$$code);
}
rerenderEditor() {
this.codeEdtor?.layout?.();
Expand Down

0 comments on commit b825cae

Please sign in to comment.