Reverses the order of either selected lines, or the entire document if nothing is selected.
Here it is with nicer syntax highlighting: http://pastebin.com/nG9zeBkW
defreverseAllLines():lines=editor.getText().splitlines()lines.reverse()editor.setText(os.linesep.join(lines))defreverseSelectedLines():importosstaline=editor.lineFromPosition(editor.getSelectionStart())endline=editor.lineFromPosition(editor.getSelectionEnd())start=editor.positionFromLine(staline)end=editor.positionFromLine(endline)+editor.lineLength(endline)text=editor.getTextRange(start,end)iftext.endswith(os.linesep):eol=os.linesepelse:eol=''lines=text.splitlines()lines.reverse()text=os.linesep.join(lines)+eoleditor.setSelection(start,end)editor.replaceSel(text)editor.setSelection(start,end)#keep selection after replaceeditor.beginUndoAction()ifeditor.getSelectionStart()==editor.getSelectionEnd():reverseAllLines()else:reverseSelectedLines()editor.endUndoAction()
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Reverses the order of either selected lines, or the entire document if nothing is selected.
Here it is with nicer syntax highlighting: http://pastebin.com/nG9zeBkW
thank you so much!
please help. how to use this? where to copy this code?
for me this script run in both mode when i put "Import os" at the beginning.