I'm adding some text to the Monaco editor using a button outside it (i.e. "hello world") and then I'm trying to set the cursor position to the next line.
I tried using the "setPosition({column:x, lineNumber:y})" function from the editor, but it doesn't work.
This is how I'm implementing it:
insertInPosition(textToInsert:string, cursorPosition:any){
this.editorInstance.setPosition(cursorPosition);
var allInstructions = this.instructionSet.split("\n")
allInstructions.splice(cursorPosition.lineNumber - 1, 0, textToInsert);
allInstructions.splice(cursorPosition.lineNumber, 1);
allInstructions = allInstructions.join("\n");
this.editorInstance.setPosition(cursorPosition);
}
I expect to see the cursor in the line and column defined by cursorPosition, but I actually see that the cursor points to line 1 and column 1 (At the top of the editor).
I also tried to use the same api editor.setPosition() inside the onDidChangeModelContent() method, but it doesn't works. And when I print in console the editor.getPosition() I receive the correct positions.
Any idea on what could be wrong?