Page 1 of 1

Inserting New Lines

Posted: Tue Jan 28, 2014 5:22 pm
by Jor'Mox
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:
Code: [show] | [select all] lua
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":
Code: [show] | [select all] lua
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:
Code: [show] | [select all] lua
local function insertNewLine()
	local curNum = getLineNumber()
	insertText("\n")
	wrapLine(curNum)
	moveCursor(0,curNum+1)
	selectCurrentLine()
	replace("")
end

Re: Inserting New Lines

Posted: Tue Jan 28, 2014 8:08 pm
by Vadi
I don't get duplication, but the newlines do not get interpreted - so you need to use wrapLine:
Code: [show] | [select all] lua
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
wrapLine("main", getLineNumber())

Re: Inserting New Lines

Posted: Tue Jan 28, 2014 8:42 pm
by Jor'Mox
If I use this function instead of the one I posted, I get the lines written in order, and then in reverse order, six lines instead of three.
Code: [show] | [select all] lua
local function insertNewLine()
        local curNum = getLineNumber()
        insertText("\n")
        wrapLine(curNum)
        moveCursor(0,curNum+1)
end
So, I'm going to assume that the duplication issue has been fixed in the next release?

Re: Inserting New Lines

Posted: Tue Jan 28, 2014 9:24 pm
by Vadi
I think it has been, there was some fix about that.