       @sendGrammar()
       @syncGrammars()
       @shareCurrentFile(buffer)
-
       @receiveFriendInfo(data)
-
       @pairingChannel.trigger 'client-broadcast-initial-marker', {colour: @markerColour}
 
-    @pairingChannel.bind 'client-broadcast-initial-marker', (data) =>
-      @receiveFriendInfo(data)
+    @pairingChannel.bind 'client-broadcast-initial-marker', (data) => @receiveFriendInfo(data)
 
     @pairingChannel.bind 'client-text-select', (data) =>
       @clearMarkers(data.colour)

    @subscriptions.dispose()

  disconnect: ->
    @pusher.disconnect()
    @clearMarkers(@markerColour)
    @hidePanel()

  serialize: ->

      @editor.setGrammar(grammar)
      @syncGrammars()

    @pairingChannel.bind 'client-share-whole-file', (file) =>
      @triggerPush = false
      buffer.setText(file)
      @triggerPush = true

    @pairingChannel.bind 'client-share-partial-file', (chunk) =>
      @triggerPush = false
      buffer.append(chunk)
      @triggerPush = true

    @pairingChannel.bind 'client-change', (data) => @changeBuffer(data)

    # @pairingChannel.bind 'client-disconnected', (data) =>
    #   @clearMarkers(data.colour)
    #   disconnectView = new AlertView "Your pair buddy has left the session."
    #   atom.workspace.addModalPanel(item: disconnectView, visible: true)


    @listenToBufferChanges()
    @syncSelectionRange()

  listenToBufferChanges: ->
    @buffer.onDidChange (event) =>
      return unless @triggerPush
      deletion = !(event.newText is "\n") and (event.newText.length is 0)
      @pairingChannel.trigger 'client-change', {deletion: deletion, event: event, colour: @markerColour}

  changeBuffer: (data) ->
    newRange = Range.fromObject(data.event.newRange)
    oldRange = Range.fromObject(data.event.oldRange)
    newText = data.event.newText

    @triggerPush = false

    @clearMarkers(data.colour)

    if data.deletion
      @buffer.delete oldRange
      @editor.scrollToBufferPosition(oldRange.start)
      @addMarker oldRange.start.toArray()[0], data.colour
    else if oldRange.containsRange(newRange)
      @buffer.setTextInRange oldRange, newText
      @editor.scrollToBufferPosition(oldRange.start)
      @addMarker oldRange.start.toArray()[0], data.colour
    else
      @buffer.insert newRange.start, newText
      @editor.scrollToBufferPosition(newRange.start)
      @addMarker(newRange.end.toArray()[0], data.colour)

    @triggerPush = true

  syncSelectionRange: ->
    @editor.onDidChangeSelectionRange (event) =>
      rows = event.newBufferRange.getRows()
      return unless rows.length > 1
