     new Range(point, Point.INFINITY)
 
   isLinewise: ->
-    for s in @editor.getSelections() when not @isWholeLine s.getBufferRange()
-      return false
-    true
+    @editor.getSelections().every (s) =>
+      @isLinewiseRange s.getBufferRange()
 
   eachSelection: (callback) ->
-    for selection in @editor.getSelections()
-      callback selection
-    if @isLinewise() and @vimState.isMode('visual', ['characterwise', 'blockwise'])
+    for s in @editor.getSelections()
+      callback s
+    if @isLinewise() and not @vimState.isMode('visual', 'linewise')
       @vimState.activate('visual', 'linewise')
+    @isIncludeNonEmptySelection()
+
+  isIncludeNonEmptySelection: ->
     @editor.getSelections().some((s) -> not s.isEmpty())
+
+  sortRanges: (ranges) ->
+    ranges.sort((a, b) -> a.compare(b))
+
+  setBufferRangeSafely: (selection, range) ->
+    if range
+      selection.setBufferRange(range)
 
 # Word
 # -------------------------

  @extend()
  select: ->
    @editor.selectAll()
    @editor.getLastSelection().isEmpty()

module.exports = {
  Word, WholeWord,

      @selectExclusive(selection, wordRegex)
      @selectInclusive(selection) if @inclusive

  selectExclusive: (s, wordRegex) ->
    @setBufferRangeSafely s, s.cursor.getCurrentWordBufferRange({wordRegex})

  selectInclusive: (selection) ->
    scanRange = selection.cursor.getCurrentLineBufferRange()
