   # - 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.
+  #  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)

  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

        if range.start.isGreaterThan(point)
          return range # Forwarding
      return rangesSameRow[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 by following order
  #  1. Occurrence under original cursor position
  #  2. forwarding in same row
  #  3. first occurrence in same row
