[wingide-users] oddness when sorting lines
Wingware Support
support at wingware.com
Thu May 24 08:32:49 MDT 2012
Campbell McKellar-Basset wrote:
> I have a binding for 'sort-selected' and a file containing these three lines:
>
> 1 import second
> 2 import first
> 3<blank line>
>
> If I select only the first two and hit sort, the blank line following
> them is sorted above the selected lines. This is usually not what I
> mean to do, and it isn't the way other actions work on selected text.
> Selecting one less line, also results in incorrect behaviour. I can
> only sort 'correctly' by very carefully selecting the lines (starting
> with the cursor positioned on the last character of the last line, and
> drag-selecting upwards).
Yea, it looks like this command is buggy. I've fixed this for Wing
4.1.7 and have appended the corrected command implementation below my
signature (it is in scripts/editor-extensions.py in your Wing installation).
Thanks for reporting this.
--
Stephan Deibel
Wingware | Python IDE
Advancing Software Development
www.wingware.com
--------------------------------------------------------
def sort_selected(app=wingapi.kArgApplication):
"""Sort selected lines of text alphabetically"""
editor = app.GetActiveEditor()
doc = editor.GetDocument()
eol = editor.GetEol()
start, end = editor.GetSelection()
start_lineno = doc.GetLineNumberFromPosition(start)
end_lineno = doc.GetLineNumberFromPosition(end)
end_line_pos = doc.GetLineStart(end_lineno)
if end_line_pos == end:
end_lineno -= 1
if end_lineno <= start_lineno:
return
line_start = doc.GetLineStart(start_lineno)
line_end = doc.GetLineEnd(end_lineno)
text = doc.GetCharRange(line_start, line_end).split(eol)
text.sort()
doc.BeginUndoAction()
try:
doc.DeleteChars(line_start, line_end-1)
doc.InsertChars(line_start, eol.join(text))
finally:
doc.EndUndoAction()
editor.SetSelection(line_start, line_end)
More information about the wingide-users
mailing list