The following script tries to provide a fillDown function:
In a rectangular, multi line selection insert the selected text on the first line in front of the selections of the subsequent lines. Any improvements are highly appreciated!
import pn
import scintilla
import string
from pypn.decorators import script
@script("FillDown", "MyScripts")
def fillDown():
editor = scintilla.Scintilla(pn.CurrentDoc())
editor.BeginUndoAction()
if editor.SelectionIsRectangle:
posStart = editor.SelectionStart
posEnd = editor.SelectionEnd
firstLine = editor.LineFromPosition(posStart)
lastLine = editor.LineFromPosition(posEnd)
text = editor.GetText(editor.GetLineSelStartPosition(firstLine),
editor.GetLineSelEndPosition(firstLine))
corr = 0
if editor.CurrentPos != posStart:
corr = len(str(text))
editor.GotoPos(posStart)
for i in range(firstLine, lastLine):
editor.LineDown()
editor.GotoPos(editor.CurrentPos - corr)
editor.AddText(len(str(text)), str(text))
else:
pn.AddOutput("no rectangular selection found")
editor.EndUndoAction()