Monaco-editor: How to replace content dynamically

Created on 7 Sep 2016  路  2Comments  路  Source: microsoft/monaco-editor

Hi,
I'm trying to replace dynamically part of the monaco-editor content within a given range with other content.
For example, I would like to replace "append" with "prepend" dynamically, in a button click.

$("#my_div").append($("<div></div>"));

Is there any way to do it?

Most helpful comment

thank you @alexandrudima, you gave me a direction to the solution. i eventually used editor.executeEdits.
So, the full solution for my problem above:

editor.executeEdits("", [
     { range: new monaco.Range(1,14,1,20), text: "prepend" }
]);

All 2 comments

you can call editor.applyEdits where you can pass in an array of edits described in IIdentifiedSingleEditOperation. You can control the undo-redo behaviour via editor.pushUndoStop

thank you @alexandrudima, you gave me a direction to the solution. i eventually used editor.executeEdits.
So, the full solution for my problem above:

editor.executeEdits("", [
     { range: new monaco.Range(1,14,1,20), text: "prepend" }
]);
Was this page helpful?
0 / 5 - 0 ratings