       @createMark(cursorPoint)
 
   selectToMark: ->
-    if @marker?
-      markPoint   = @marker.getHeadBufferPosition()
+    if @decoration
+      markPoint   = @decoration?.getMarker().getHeadBufferPosition()
       cursorPoint = @editor.getCursorBufferPosition()
       if not cursorPoint.isEqual(markPoint)
         @editor.setSelectedBufferRange([markPoint, cursorPoint])
 
   gotoMark: ->
-    if @marker?
-      @editor.setCursorBufferPosition(@marker.getHeadBufferPosition())
+    if @decoration
+      @editor.setCursorBufferPosition(@decoration.getMarker().getHeadBufferPosition())
 
   swapWithMark: ->
-    if @marker?
+    if @decoration
       cursorPoint = @editor.getCursorBufferPosition()
-      markPoint   = @marker.getHeadBufferPosition()
+      markPoint   = @decoration.getMarker().getHeadBufferPosition()
       if not cursorPoint.isEqual(markPoint)
-        @gutter.removeClassFromLine(markPoint.row, 'marked')
-        @marker.setHeadBufferPosition(cursorPoint)
+        @decoration.getMarker().setHeadBufferPosition(cursorPoint)
         @editor.setCursorBufferPosition(markPoint)

    @subscribeToCommand editorView, 'mark:goto-mark', => @gotoMark()
    @subscribeToCommand editorView, 'mark:swap', => @swapWithMark()

  updateGutter: ->
    if @marker?
      @gutter.addClassToLine(@marker.getHeadBufferPosition().row, 'marked')

  createMark: (point) ->
    @marker = @editor.markBufferPosition(point)
    @gutter.addClassToLine(point.row, 'marked')

    @subscribe @marker, 'changed', ({ isValid }) =>
      if not isValid
        @unsubscribe(@marker)
        @marker.destroy()
        @marker = undefined

  clearMark: () ->
    if @marker
      @gutter.removeClassFromLine(@marker.getHeadBufferPosition().row, 'marked')
      @marker.destroy()
      @marker = undefined

  toggle: ->
    if not @gutter.isVisible
      return

    markPoint = @marker?.getHeadBufferPosition()
    cursorPoint = @editor.getCursorBufferPosition()

    if markPoint?

  constructor: (editorView) ->
    {@editor, @gutter} = editorView

    @decoration = undefined

    @subscribe @editor, 'destroyed', => @unsubscribe()
    @subscribeToCommand editorView, 'mark:toggle', => @toggle()
    @subscribeToCommand editorView, 'mark:clear-mark', => @clearMark()
