How to use the @jupyterlab/codeeditor.CodeEditor.Model function in @jupyterlab/codeeditor

To help you get started, we’ve selected a few @jupyterlab/codeeditor 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 jupyterlab / jupyterlab / packages / settingeditor / src / raweditor.ts View on Github external
constructor(options: RawEditor.IOptions) {
    super({
      orientation: 'horizontal',
      renderer: SplitPanel.defaultRenderer,
      spacing: 1
    });

    const { commands, editorFactory, registry } = options;

    this.registry = registry;
    this._commands = commands;

    // Create read-only defaults editor.
    const defaults = (this._defaults = new CodeEditorWrapper({
      model: new CodeEditor.Model(),
      factory: editorFactory
    }));

    defaults.editor.model.value = '';
    defaults.editor.model.mimeType = 'text/javascript';
    defaults.editor.setOption('readOnly', true);

    // Create read-write user settings editor.
    const user = (this._user = new CodeEditorWrapper({
      model: new CodeEditor.Model(),
      factory: editorFactory,
      config: { lineNumbers: true }
    }));

    user.addClass(USER_CLASS);
    user.editor.model.mimeType = 'text/javascript';
github jupyter / nbdime / packages / nbdime / src / common / editor.ts View on Github external
constructor(value?: string, options?: Partial) {
    if (options && options.readOnly) {
      // Prevent readonly editor from trapping tabs
      options.extraKeys = {Tab: false, 'Shift-Tab': false};
    }
    super({
      model: new CodeEditor.Model({value}),
      factory: function() {
        let factory = new CodeMirrorEditorFactory(options);
        return factory.newInlineEditor.bind(factory);
      }()
    });
    this.staticLoaded = false;
    EditorWidget.editors.push(this.cm);
  }
github jupyterlab / jupyterlab-data-explorer / tests / test-codeeditor / src / editor.spec.ts View on Github external
it('should create a CodeEditor Model with an initial value', () => {
      let other = new CodeEditor.Model({ value: 'Initial text here' });
      expect(other).to.be.an.instanceof(CodeEditor.Model);
      expect(other.value.text).to.equal('Initial text here');
      other.dispose();
    });
github jupyterlab / jupyterlab / tests / test-console / src / history.spec.ts View on Github external
it('should be called upon an editor edge request', async () => {
        const history = new TestHistory({ session });
        expect(history.methods).to.not.contain('onEdgeRequest');
        const host = document.createElement('div');
        const model = new CodeEditor.Model();
        const editor = new CodeMirrorEditor({ model, host });
        history.editor = editor;
        history.push('foo');
        const promise = signalToPromise(editor.model.value.changed);
        editor.edgeRequested.emit('top');
        expect(history.methods).to.contain('onEdgeRequest');
        await promise;
        expect(editor.model.value.text).to.equal('foo');
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-codeeditor / src / editor.spec.ts View on Github external
it('should create a CodeEditor Model with an initial mimetype', () => {
      let other = new CodeEditor.Model({
        value: 'import this',
        mimeType: 'text/x-python'
      });
      expect(other).to.be.an.instanceof(CodeEditor.Model);
      expect(other.mimeType).to.equal('text/x-python');
      expect(other.value.text).to.equal('import this');
      other.dispose();
    });
  });
github jupyterlab / jupyterlab / tests / test-completer / src / handler.spec.ts View on Github external
function createEditorWidget(): CodeEditorWrapper {
  const model = new CodeEditor.Model();
  const factory = (options: CodeEditor.IOptions) => {
    return new CodeMirrorEditor(options);
  };
  return new CodeEditorWrapper({ factory, model });
}
github jupyterlab / jupyterlab / tests / test-completer / src / widget.spec.ts View on Github external
function createEditorWidget(): CodeEditorWrapper {
  let model = new CodeEditor.Model();
  let factory = (options: CodeEditor.IOptions) => {
    return new CodeMirrorEditor(options);
  };
  return new CodeEditorWrapper({ factory, model });
}
github jupyterlab / jupyterlab-data-explorer / tests / test-completer / src / widget.spec.ts View on Github external
function createEditorWidget(): CodeEditorWrapper {
  let model = new CodeEditor.Model();
  let factory = (options: CodeEditor.IOptions) => {
    return new CodeMirrorEditor(options);
  };
  return new CodeEditorWrapper({ factory, model });
}
github krassowski / jupyterlab-lsp / packages / jupyterlab-lsp / src / adapters / codemirror / testutils.ts View on Github external
constructor(
    protected language = () => 'python',
    protected path = () => 'dummy.py',
    protected file_extension = () => 'py'
  ) {
    const factoryService = new CodeMirrorEditorFactory();
    this.connections = new Map();

    this.host = document.createElement('div');
    document.body.appendChild(this.host);
    let model = new CodeEditor.Model();

    this.ce_editor = factoryService.newDocumentEditor({
      host: this.host,
      model
    });
    this.virtual_editor = new VirtualFileEditor(
      language,
      file_extension,
      path,
      this.ce_editor.editor
    );
  }