ngx-monaco-editor icon indicating copy to clipboard operation
ngx-monaco-editor copied to clipboard

Create tabs; calling `createModel({...})`

Open dnmd opened this issue 6 years ago • 6 comments

As per instructions from the monaco editor repo, the preferred method of creating tabs is;

  • create a single editor instance via monaco.editor.create({ ... , model: null })
  • create N model instances via monaco.editor.createModel(...).
  • switch tabs by calling editorInstance.setModel(modelInstance)

for each model, you can save its view state (cursor, scroll position, etc) via -

  • editorInstance.saveViewState() and restore it via editorInstance.restoreViewState().

But I get stuck at the second step, as I am not able to create multiple instance. Am I missing something or is this simply not implemented (yet)? Thanks in advance

dnmd avatar Oct 22 '19 18:10 dnmd

Did you solve the issue? I have same question like you got. Calling createModel is not available.

ramseyfeng avatar Jun 18 '20 06:06 ramseyfeng

No I haven't...

dnmd avatar Jun 19 '20 10:06 dnmd

@dnmd You can wait until monaco editor is loaded, and use below way to create the model:

monaco.editor.createModel(model.value, model.language, uri)

ramseyfeng avatar Jun 19 '20 23:06 ramseyfeng

No, it's not working.

EnderCommunity avatar Aug 09 '20 04:08 EnderCommunity

Also not working for me. Got the editor instance via (onInit)="editorInitialized($event)". Here is the code from the ts file of the component:

import * as monaco from 'monaco-editor';
...
editorInitialized(editor) {
        let model = monaco.editor.createModel("Hello");
        editor.setModel(model)
}

But the editor simply gets blank when loaded. Maybe the global editor "scope" of the monaco.editor.createModel call and the scope of the monaco.editor.IStandaloneCodeEditor instance from ngx-monaco-editor is different? Can somebody help?

thmang82 avatar Oct 11 '20 21:10 thmang82

Turns out, it works when using the monaco instance that ngx-monaco-editor loads internally:

...
editorInitialized(editor) {
    let monaco = window.monaco;
    let model = monaco.editor.createModel("Hello");
    editor.setModel(model)
}

thmang82 avatar Oct 11 '20 21:10 thmang82