Adds clarification comments

This commit is contained in:
Robert Paul 2017-08-08 14:02:29 -05:00
parent d76940dabc
commit 791c62a3ba

View file

@ -440,16 +440,20 @@ class Ex
sort: ({ range }) => sort: ({ range }) =>
editor = atom.workspace.getActiveTextEditor() editor = atom.workspace.getActiveTextEditor()
sortingRange = [[]] sortingRange = [[]]
# If no range is provided, the entire file should be sorted.
isMultiLine = range[1] - range[0] > 1 isMultiLine = range[1] - range[0] > 1
if isMultiLine if isMultiLine
sortingRange = [[range[0], 0], [range[1] + 1, 0]] sortingRange = [[range[0], 0], [range[1] + 1, 0]]
else else
sortingRange = [[0, 0], [editor.getLastBufferRow(), 0]] sortingRange = [[0, 0], [editor.getLastBufferRow(), 0]]
# Store every bufferedRow string in an array.
textLines = [] textLines = []
for lineIndex in [sortingRange[0][0]..sortingRange[1][0] - 1] for lineIndex in [sortingRange[0][0]..sortingRange[1][0] - 1]
textLines.push(editor.lineTextForBufferRow(lineIndex)) textLines.push(editor.lineTextForBufferRow(lineIndex))
# Sort the array and join them together with newlines for writing back to the file.
sortedText = _.sortBy(textLines).join('\n') + '\n' sortedText = _.sortBy(textLines).join('\n') + '\n'
editor.buffer.setTextInRange(sortingRange, sortedText) editor.buffer.setTextInRange(sortingRange, sortedText)