I have been trying to write text above the current working line via a trigger, and it needs to play nicely with other possibly present text (obviously). The problem is that when I use insertText("\n") a duplicate of the line I just wrote. I can "fix" it, but it is a bit cumbersome. Is there something I'm missing here, or is it a bug that is either already known and being addressed, or unknown?
Example code:
moveCursor(0,getLineNumber()-1)
insertText("\nblah") -- shows "blah" on the line, as expected
insertText("\nmore blah") -- now shows three lines, instead of two as expected, blah, blah, and more blah
My current "fix":
function insertNewLine()
insertText("\n")
selectString(getCurrentLine(),1)
replace("")
end
moveCursor(0,getLineNumber()-1)
insertNewLine()
insertText("blah")
insertNewLine()
insertText("more blah")
Edit:
The above code worked fine when testing with an alias, but didn't work at all in a trigger (which I found unusual). As a result, I adjusted the code until I achieved the desired result, below:
local function insertNewLine()
local curNum = getLineNumber()
insertText("\n")
wrapLine(curNum)
moveCursor(0,curNum+1)
selectCurrentLine()
replace("")
end