How to use the monaco-editor.editor.createModel function in monaco-editor

To help you get started, we’ve selected a few monaco-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gitlabhq / gitlabhq / app / assets / javascripts / editor / editor_lite.js View on Github external
instance,
    isDiff,
  } = {}) {
    if (!instance) {
      return null;
    }
    const uriFilePath = joinPaths(URI_PREFIX, blobGlobalId, blobPath);
    const uri = Uri.file(uriFilePath);
    const existingModel = monacoEditor.getModel(uri);
    const model = existingModel || monacoEditor.createModel(blobContent, undefined, uri);
    if (!isDiff) {
      instance.setModel(model);
      return model;
    }
    const diffModel = {
      original: monacoEditor.createModel(
        blobOriginalContent,
        EditorLite.getModelLanguage(model.uri.path),
      ),
      modified: model,
    };
    instance.setModel(diffModel);
    return diffModel;
  }
github gitlabhq / gitlabhq / app / assets / javascripts / ide / lib / common / model.js View on Github external
constructor(file, head = null) {
    this.disposable = new Disposable();
    this.file = file;
    this.head = head;
    this.content = file.content !== '' || file.deleted ? file.content : file.raw;
    this.options = { ...defaultModelOptions };

    this.disposable.add(
      (this.originalModel = monacoEditor.createModel(
        head ? head.content : this.file.raw,
        undefined,
        new Uri('gitlab', false, `original/${this.path}`),
      )),
      (this.model = monacoEditor.createModel(
        this.content,
        undefined,
        new Uri('gitlab', false, this.path),
      )),
    );
    if (this.file.mrChange) {
      this.disposable.add(
        (this.baseModel = monacoEditor.createModel(
          this.file.baseRaw,
          undefined,
          new Uri('gitlab', false, `target/${this.path}`),
github Leko / type-puzzle / packages / playground / src / models.ts View on Github external
import { Uri, editor } from "monaco-editor";
import defaultCode from "raw-loader!./assets/main.txt";
import defaultTSConfig from "raw-loader!./assets/tsconfig.txt";

export const codeEditorModel = editor.createModel(
  defaultCode,
  "typescript",
  Uri.parse("file:///main.tsx")
);

export const tsConfigEditorModel = editor.createModel(
  defaultTSConfig,
  "json",
  Uri.parse("file:///tsconfig.json")
);
github Leko / type-puzzle / packages / playground / src / models.ts View on Github external
import { Uri, editor } from "monaco-editor";
import defaultCode from "raw-loader!./assets/main.txt";
import defaultTSConfig from "raw-loader!./assets/tsconfig.txt";

export const codeEditorModel = editor.createModel(
  defaultCode,
  "typescript",
  Uri.parse("file:///main.tsx")
);

export const tsConfigEditorModel = editor.createModel(
  defaultTSConfig,
  "json",
  Uri.parse("file:///tsconfig.json")
);
github gitlabhq / gitlabhq / app / assets / javascripts / ide / lib / common / model.js View on Github external
constructor(file, head = null) {
    this.disposable = new Disposable();
    this.file = file;
    this.head = head;
    this.content = file.content !== '' || file.deleted ? file.content : file.raw;
    this.options = { ...defaultModelOptions };

    this.disposable.add(
      (this.originalModel = monacoEditor.createModel(
        head ? head.content : this.file.raw,
        undefined,
        new Uri('gitlab', false, `original/${this.path}`),
      )),
      (this.model = monacoEditor.createModel(
        this.content,
        undefined,
        new Uri('gitlab', false, this.path),
      )),
    );
    if (this.file.mrChange) {
      this.disposable.add(
        (this.baseModel = monacoEditor.createModel(
          this.file.baseRaw,
          undefined,
          new Uri('gitlab', false, `target/${this.path}`),
        )),
      );
    }

    this.events = new Set();
github gitlabhq / gitlabhq / app / assets / javascripts / ide / lib / common / model.js View on Github external
this.disposable.add(
      (this.originalModel = monacoEditor.createModel(
        head ? head.content : this.file.raw,
        undefined,
        new Uri('gitlab', false, `original/${this.path}`),
      )),
      (this.model = monacoEditor.createModel(
        this.content,
        undefined,
        new Uri('gitlab', false, this.path),
      )),
    );
    if (this.file.mrChange) {
      this.disposable.add(
        (this.baseModel = monacoEditor.createModel(
          this.file.baseRaw,
          undefined,
          new Uri('gitlab', false, `target/${this.path}`),
        )),
      );
    }

    this.events = new Set();

    this.updateContent = this.updateContent.bind(this);
    this.updateNewContent = this.updateNewContent.bind(this);
    this.dispose = this.dispose.bind(this);

    eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose);
    eventHub.$on(`editor.update.model.content.${this.file.key}`, this.updateContent);
    eventHub.$on(`editor.update.model.new.content.${this.file.key}`, this.updateNewContent);
github gitlabhq / gitlabhq / app / assets / javascripts / editor / editor_lite.js View on Github external
static createEditorModel({
    blobPath,
    blobContent,
    blobOriginalContent,
    blobGlobalId,
    instance,
    isDiff,
  } = {}) {
    if (!instance) {
      return null;
    }
    const uriFilePath = joinPaths(URI_PREFIX, blobGlobalId, blobPath);
    const uri = Uri.file(uriFilePath);
    const existingModel = monacoEditor.getModel(uri);
    const model = existingModel || monacoEditor.createModel(blobContent, undefined, uri);
    if (!isDiff) {
      instance.setModel(model);
      return model;
    }
    const diffModel = {
      original: monacoEditor.createModel(
        blobOriginalContent,
        EditorLite.getModelLanguage(model.uri.path),
      ),
      modified: model,
    };
    instance.setModel(diffModel);
    return diffModel;
  }