Creating a new line

I’m creating a plugin in typescript and I can’t seem to find a very simple function in the api to create a newline.

for example:
line1: text
line2: text

I want to set a line between line1 and line2.
So expected would be new text at line2 and line2 would be moved to line3 or aka a new line created.

However using the function setLine(linenumber, text) will overwrite the text at that current linenumber if there is any, I also tried ‘\n + text’ to create a new line but the ‘\n’ is overwritten on the current text aswell;. The replaceSelection function doesn’t work for me either.

So any idea on How to create a new line with the api?

More generally, if you want to insert text as the lineNumber-th line,

editor.replaceRange(text + "\n", { line: lineNumber, ch: 0 });