Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular ngx-monaco-editor #60

Open
cnrishiraj opened this issue Aug 22, 2024 · 0 comments
Open

Angular ngx-monaco-editor #60

cnrishiraj opened this issue Aug 22, 2024 · 0 comments

Comments

@cnrishiraj
Copy link

cnrishiraj commented Aug 22, 2024

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();
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant