       while selections.length > 0
         # Find selections spanning a contiguous set of lines
         selection = selections.shift()
-        lastSelectionRange = selection.getBufferRange()
         selectionsToMove = [selection]
-        rangesOfSelectionsToMove = [lastSelectionRange]
-
-        while lastSelectionRange.end.row is selections[0]?.getBufferRange().start.row
+
+        while selection.end.row is selections[0]?.start.row
           selection = selections.shift()
-          lastSelectionRange = selection.getBufferRange()
           selectionsToMove.push(selection)
-          rangesOfSelectionsToMove.push(lastSelectionRange)
 
         # Compute the range spanned by all these selections...
-        linesRangeStart = [selectionsToMove[0].getBufferRange().start.row, 0]
-        if lastSelectionRange.end.row > lastSelectionRange.start.row and lastSelectionRange.end.column is 0
+        linesRangeStart = [selection.start.row, 0]
+        if selection.end.row > selection.start.row and selection.end.column is 0
           # Don't move the last line of a multi-line selection if the selection ends at column 0
-          linesRange = new Range(linesRangeStart, lastSelectionRange.end)
+          linesRange = new Range(linesRangeStart, selection.end)
         else
-          linesRange = new Range(linesRangeStart, [lastSelectionRange.end.row + 1, 0])
+          linesRange = new Range(linesRangeStart, [selection.end.row + 1, 0])
 
         # If selected line range is preceded by a fold, one line above on screen
         # could be multiple lines in the buffer.

  # Move lines intersection the most recent selection or multiple selections up by one row in screen
  # coordinates.
  moveLineUp: ->
    selections = @getSelectionsOrderedByBufferPosition()

    if selections[0].getBufferRange().start.row is 0
      return

    if selections[selections.length - 1].getBufferRange().start.row is @getLastBufferRow() and @buffer.getLastLine() is ''
      return

    @transact =>


        # Make sure the inserted text doesn't go into an existing fold
        if fold = @displayBuffer.largestFoldStartingAtBufferRow(precedingBufferRow)
          rangesToRefold.push(fold.getBufferRange().translate([linesRange.getRowCount() - 1, 0]))
          fold.destroy()

        # Delete lines spanned by selection and insert them on the preceding buffer row
