Skip to content

Angular ngx-monaco-editor #60

@cnrishiraj

Description

@cnrishiraj

I am trying to use this plugin for my editor based project using ngx-monaco-editor, i want to grey out the blocked json/code with a color so that user can know they cant edit that particular block, need ideas and help, below is the sample code.

<ngx-monaco-editor class="textarea" [options]="Options" id="editor" (onInit)="EditorInit($event)" [(ngModel)]="Title"></ngx-monaco-editor>

DataEditorInit(monacoInstance: any): void {
    const monacoModel = monacoInstance.getModel();
    const jsonString = this.processedDataTitle;
    const objectToFind = 'segments';
    const offset = jsonString.indexOf(objectToFind);
    if (offset != -1) {
      const position = monacoModel.getPositionAt(offset);
      const startLineNumber = position.lineNumber;
      const segmentJsonString = jsonString.substring(offset);
      const endLineNumber = this.getEndLineNumber(
        startLineNumber,
        segmentJsonString
      );
      const constrainedInstance = constrainedEditor.constrainedEditor(
        window['monaco']
      );
      constrainedInstance.initializeIn(monacoInstance);
      const restrictions = [
        {
          range: [startLineNumber, 1, endLineNumber, 1],
          label: 'segments',
          allowMultiline: false,
        },
      ];
      constrainedInstance.addRestrictionsTo(monacoModel, restrictions);
      monacoModel.toggleHighlightOfEditableAreas();
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions