Skip to content

Commit

Permalink
chore(edit-content): fix problem with editor #29875
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Oct 24, 2024
1 parent 01a4246 commit 08e04f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ngx-monaco-editor
[class.file-field__code-editor--disabled]="form.disabled"
[options]="store.monacoConfig()"
(init)="onEditorInit($event)"
class="file-field__code-editor"
data-testId="code-editor"
formControlName="content" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

:host ::ng-deep {
.editor-container {
position: absolute;
position: absolute !important;
top: 0;
left: 0;
right: 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
MonacoEditorComponent,
MonacoEditorConstructionOptions,
MonacoEditorModule
} from '@materia-ui/ngx-monaco-editor';
Expand All @@ -9,9 +8,9 @@ import {
Component,
effect,
inject,
viewChild,
OnInit,
untracked
untracked,
Injector
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
Expand Down Expand Up @@ -74,6 +73,8 @@ export class DotFormFileEditorComponent implements OnInit {
*/
readonly #dialogConfig = inject(DynamicDialogConfig<DialogProps>);

readonly #injector = inject(Injector);

/**
* Form group for the file editor component.
*
Expand All @@ -94,7 +95,7 @@ export class DotFormFileEditorComponent implements OnInit {
*
* @type {MonacoEditorComponent}
*/
$editorRef = viewChild.required(MonacoEditorComponent);
#editorRef: monaco.editor.IStandaloneCodeEditor | null = null;

constructor() {
effect(() => {
Expand Down Expand Up @@ -221,9 +222,12 @@ export class DotFormFileEditorComponent implements OnInit {
* @private
*/
#disableEditor() {
if (!this.#editorRef) {
return
}

this.form.disable();
const editor = this.$editorRef().editor;
editor.updateOptions({ readOnly: true });
this.#editorRef.updateOptions({ readOnly: true });
}

/**
Expand All @@ -235,9 +239,12 @@ export class DotFormFileEditorComponent implements OnInit {
* 3. Updates the editor options to make it writable (readOnly: false).
*/
#enableEditor() {
if (!this.#editorRef) {
return
}

this.form.enable();
const editor = this.$editorRef().editor;
editor.updateOptions({ readOnly: false });
this.#editorRef.updateOptions({ readOnly: false });
}

/**
Expand Down Expand Up @@ -267,4 +274,8 @@ export class DotFormFileEditorComponent implements OnInit {
cancelUpload(): void {
this.#dialogRef.close();
}

onEditorInit(editor: monaco.editor.IStandaloneCodeEditor) {
this.#editorRef = editor;
}
}

0 comments on commit 08e04f0

Please sign in to comment.