Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70d98d3

Browse files
committed
improved code editor api
1 parent 871d05c commit 70d98d3

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

projects/code-editor/src/lib/code-editor/code-editor.component.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ export class CodeEditorComponent
4848
}
4949
};
5050

51+
/**
52+
* The instance of the editor.
53+
*/
54+
get editor(): editor.IEditor {
55+
return this._editor;
56+
}
57+
58+
protected set editor(value: editor.IEditor) {
59+
this._editor = value;
60+
}
61+
5162
@ViewChild('editor', { static: true })
5263
editorContent: ElementRef<HTMLDivElement>;
5364

@@ -118,9 +129,9 @@ export class CodeEditorComponent
118129
protected jsonDefaults = inject(JsonDefaultsService);
119130

120131
ngOnDestroy() {
121-
if (this._editor) {
122-
this._editor.dispose();
123-
this._editor = null;
132+
if (this.editor) {
133+
this.editor.dispose();
134+
this.editor = null;
124135
}
125136

126137
if (this._model) {
@@ -135,8 +146,8 @@ export class CodeEditorComponent
135146
}
136147

137148
if (changes.readOnly && !changes.readOnly.firstChange) {
138-
if (this._editor) {
139-
this._editor.updateOptions({
149+
if (this.editor) {
150+
this.editor.updateOptions({
140151
readOnly: changes.readOnly.currentValue
141152
});
142153
}
@@ -149,8 +160,8 @@ export class CodeEditorComponent
149160

150161
@HostListener('window:resize')
151162
onResize() {
152-
if (this._editor) {
153-
this._editor.layout();
163+
if (this.editor) {
164+
this.editor.layout();
154165
}
155166
}
156167

@@ -180,7 +191,7 @@ export class CodeEditorComponent
180191
model: this._model
181192
});
182193

183-
this._editor = monaco.editor.create(domElement, options);
194+
this.editor = monaco.editor.create(domElement, options);
184195

185196
this._model.onDidChangeContent((e: editor.IModelContentChangedEvent) => {
186197
this.modelContentChanged.emit(e);

0 commit comments

Comments
 (0)