       selection = _.first @editor.selectWord()
       return unless selection
 
-      @adjustSelectionForDot(selection)
-
-      selection.insertText(match.completion)
-      @editor.selectWord()
+      @insertMatch(match)
 
   selectNextItemView: ->
     super

      @css(left: left, top: potentialTop, bottom: 'inherit')

  confirmed: (item) ->
    {replacementOffset} = @autocompleteInfo.params
    {buffer} = @editor
    {selectionOffset} = item

    @cancel()

    startPos = buffer.positionForCharacterIndex(replacementOffset)
    endPos   = buffer.positionForCharacterIndex(replacementOffset + selectionOffset)
    range    = new Range(startPos, endPos)

    # TODO: replace when analysis_server is fixed (?)
    # Or I might be using it wrong. Whatever.
    # if replacementOffset were accurate, we'd use the following:
    # @editor.setTextInBufferRange range, item.completion
    # instead, we make a gamble that all completions are word-based:
    selection = _.first @editor.selectWord()
    @adjustSelectionForDot(selection)
    selection?.insertText(item.completion)

  cancelled: ->
    super

    super
    false

  insertMatch: (item) =>
    {replacementOffset} = @autocompleteInfo.params
    {buffer} = @editor
    {selectionOffset} = item

    pos = @editor.getCursorBufferPosition()

    cursorOffset  = buffer.characterIndexForPosition(pos)
    startPos      = buffer.positionForCharacterIndex(replacementOffset)
    # endPos        = buffer.positionForCharacterIndex(replacementOffset + selectionOffset)
    endPos        = @editor.getCursorBufferPosition()
    range         = new Range(startPos, endPos)

    @editor.setSelectedBufferRange(range)
    @editor.insertText(item.completion)
    
    console.log 'replacementOffset', replacementOffset, 'for item', item
    console.log 'Range is', range
