Modifies sort function and adds a unit test

This commit is contained in:
Robby 2017-08-06 23:22:13 -05:00
parent 15296ff369
commit 4312777508
2 changed files with 23 additions and 4 deletions

View file

@ -438,10 +438,19 @@ class Ex
optionProcessor()
sort: ({ range }) =>
range = [[range[0], 0], [range[1] + 1, 0]]
editor = atom.workspace.getActiveTextEditor()
text = editor.getTextInBufferRange(range)
sortedText = _.sortBy(text.split(/\n/)).join('\n')
editor.buffer.setTextInRange(range, sortedText)
sortingRange = [[]]
isMultiLine = range[1] - range[0] > 1
if isMultiLine
sortingRange = [[range[0], 0], [range[1] + 1, 0]]
else
sortingRange = [[0, 0], [editor.getLastBufferRow(), 0]]
textLines = []
for lineIndex in [sortingRange[0][0]..sortingRange[1][0] - 1]
textLines.push(editor.lineTextForBufferRow(lineIndex))
sortedText = _.sortBy(textLines).join('\n') + '\n'
editor.buffer.setTextInRange(sortingRange, sortedText)
module.exports = Ex