   getRangeForLastSelection: (ranges) ->
     point = @vimState.getOriginalCursorPosition()
 
-    rangesSameRow = ranges.filter (range) -> range.start.row is point.row
-    if rangesSameRow.length
-      for range in rangesSameRow
-        if point.isGreaterThanOrEqual(range.start) and point.isLessThanOrEqual(range.end)
-          return range # Contained
+    for range in ranges when range.containsPoint(point)
+      return range
 
-        if range.start.isGreaterThan(point)
-          return range # Forwarding
-      return rangesSameRow[0]
+    rangesStartFromSameRow = ranges.filter((range) -> range.start.row is point.row)
+
+    if rangesStartFromSameRow.length
+      for range in rangesStartFromSameRow when range.start.isGreaterThan(point)
+        return range # Forwarding
+      return rangesStartFromSameRow[0]
 
     for range in ranges when range.start.isGreaterThan(point)  # Forwarding
       return range
+
     ranges[0] # return first as fallback

    else
      false

  # Which occurrence become lastSelection is determined in following order
  #  1. Occurrence under original cursor position
  #  2. forwarding in same row
  #  3. first occurrence in same row

  # - Return: true/false to indicate success or fail
  #
  # When startInsertMode was true, do special handling for which occurrence range
  #  become lastSelection so that autocomplete+popup shows at original cursor position or near.
  select: ({startInsertMode}={}) ->
    isVisualMode = @vimState.mode is 'visual'
    markers = @getMarkersIntersectsWithRanges(@editor.getSelectedBufferRanges(), isVisualMode)
