     @pairingChannel.trigger 'client-grammar-sync', grammar.scopeName
 
   syncMarker: ->
-    target = $('atom-text-editor#pusht::shadow .line-numbers')[0]
-    observer = new MutationObserver (mutations) =>
-      newLineNumber = @editor.getCursorBufferPosition().toArray()[0]
-      @clearMyMarkers()
-      @addMarker(newLineNumber, @markerColour)
-
-    config = {attributes: true, childList: true, characterData: true}
-
-    observer.observe target, config
+
+    lastScreenRow = @editor.getLastScreenRow()
 
     @editor.onDidChangeCursorPosition (event) =>
       if event.newBufferPosition.toArray()[0] isnt event.oldBufferPosition.toArray()[0]
-        newLineNumber = event.newBufferPosition.toArray()[0]
-        @clearMyMarkers()
-        @addMarker(newLineNumber, @markerColour)
-
-    @editor.onDidChangeSelectionRange (event) =>
-      rows = event.newBufferRange.getRows()
-      @clearMyMarkers()
-      _.each rows, (row) =>
-        @addMarker(row, @markerColour)
-
-  clearMyMarkers: ->
+        newLineNumber = @editor.getCursorScreenRow()
+        if @editor.getCursorScreenRow() > lastScreenRow
+          console.log 'expansion'
+          target = $('atom-text-editor#pusht::shadow .line-numbers')[0]
+          self = @
+          observer = new MutationObserver (mutations) ->
+            console.log mutations
+            self.clearMarkers(self.markerColour)
+            self.addMarker(newLineNumber, self.markerColour)
+            self.pairingChannel.trigger 'client-cursor-moved', {colour: self.markerColour, line: newLineNumber}
+            @disconnect()
+          config = {attributes: true, childList: true, characterData: true}
+          observer.observe target, config
+        else if @editor.getSelectedText() isnt ""
+          console.log 'selection'
+          rows = @editor.getSelectedBufferRange().getRows()
+          @clearMarkers(@markerColour)
+          @markRows(rows, @markerColour)
+        else
+          console.log 'movement'
+          @clearMarkers(@markerColour)
+          @addMarker(newLineNumber, @markerColour)
+          @pairingChannel.trigger 'client-cursor-moved', {colour: @markerColour, line: newLineNumber}
+        lastScreenRow = @editor.getLastScreenRow()
+
+
+  markRows: (rows, colour, triggerEnabled = true) ->
+    _.each rows, (row) => @addMarker(row, colour)
+    console.log 'sending selection'
+    if triggerEnabled then @pairingChannel.trigger 'client-cursor-moved', {colour: @markerColour, selection: true, rows: rows}
+
+  clearMarkers: (colour)->
     $("atom-text-editor#pusht::shadow .line-number").each (index, line) =>
-      $(line).removeClass(@markerColour)
+      $(line).removeClass(colour)
 
   addMarker: (line, colour) ->
     $("atom-text-editor#pusht::shadow .line-number-#{line}").addClass(colour)


      triggerPush = false

      if data.deletion
        buffer.delete oldRange
        @editor.scrollToBufferPosition(oldRange.start)
      else if oldRange.containsRange(newRange)
        buffer.setTextInRange oldRange, newText
        @editor.scrollToBufferPosition(oldRange.start)
      else
        buffer.insert newRange.start, newText
        @editor.scrollToBufferPosition(newRange.start)

      triggerPush = true


    @pairingChannel.bind 'client-broadcast-initial-marker', (data) =>
      @receiveFriendInfo(data)

    @pairingChannel.bind 'client-cursor-moved', (data) =>
      @clearMarkers(data.colour)
      console.log 'receiving cursor event'
      console.log data

      if data.selection then @markRows(data.rows, data.colour, false) else @addMarker(data.line, data.colour)

    @pairingChannel.bind 'client-grammar-sync', (syntax) =>
      grammar = atom.grammars.grammarForScopeName(syntax)
      @editor.setGrammar(grammar)
