diff --git a/spec/app/edit-session-replication-spec.coffee b/spec/app/edit-session-replication-spec.coffee index 1fb22ad99..198258e32 100644 --- a/spec/app/edit-session-replication-spec.coffee +++ b/spec/app/edit-session-replication-spec.coffee @@ -15,7 +15,14 @@ describe "EditSession replication", -> doc1.connect(doc2) editSession2 = deserialize(doc2) - it "replicates the selections", -> + it "replicates the initial selections", -> + expect(editSession2.getSelectedBufferRanges()).toEqual editSession1.getSelectedBufferRanges() + + it "replicates changes to selections", -> + editSession1.getLastSelection().setBufferRange([[2, 3], [4, 5]]) + expect(editSession2.getLastSelection().getBufferRange()).toEqual [[2, 3], [4, 5]] + + editSession1.addCursorAtBufferPosition([5, 6]) expect(editSession2.getSelectedBufferRanges()).toEqual editSession1.getSelectedBufferRanges() it "replicates the scroll position", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 9898a9fa4..070120b15 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -44,6 +44,7 @@ class EditSession @buffer = project.bufferForId(@state.get('bufferId')) @displayBuffer = new DisplayBuffer(@buffer, { tabLength }) + @subscribe @displayBuffer, 'marker-created', @handleMarkerCreation for marker in @findMarkers(@getSelectionMarkerAttributes()) @addSelection(marker) @@ -56,7 +57,9 @@ class EditSession version: @constructor.version scrollTop: 0 scrollLeft: 0 + @displayBuffer = new DisplayBuffer(@buffer, { tabLength }) + @subscribe @displayBuffer, 'marker-created', @handleMarkerCreation @addCursorAtScreenPosition([0, 0]) @languageMode = new LanguageMode(this, @buffer.getExtension()) @@ -69,7 +72,6 @@ class EditSession @subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted" @subscribe @buffer, "markers-updated", => @mergeCursors() @subscribe @buffer, "modified-status-changed", => @trigger "modified-status-changed" - @preserveCursorPositionOnBufferReload() @subscribe @displayBuffer, "changed", (e) => @@ -823,11 +825,8 @@ class EditSession # # Returns the new {Cursor}. addCursorAtScreenPosition: (screenPosition) -> - marker = @markScreenPosition(screenPosition, @getSelectionMarkerAttributes()) - @addSelection(marker).cursor - - getSelectionMarkerAttributes: -> - type: 'selection', editSessionId: @id, invalidation: 'never' + @markScreenPosition(screenPosition, @getSelectionMarkerAttributes()) + @getLastSelection().cursor # Adds a cursor at the provided `bufferPosition`. # @@ -835,8 +834,8 @@ class EditSession # # Returns the new {Cursor}. addCursorAtBufferPosition: (bufferPosition) -> - marker = @markBufferPosition(bufferPosition, invalidation: 'never', type: 'selection') - @addSelection(marker).cursor + @markBufferPosition(bufferPosition, @getSelectionMarkerAttributes()) + @getLastSelection().cursor # Adds a cursor to the `EditSession`. # @@ -886,9 +885,8 @@ class EditSession # # Returns the new {Selection}. addSelectionForBufferRange: (bufferRange, options={}) -> - options = _.defaults(@getSelectionMarkerAttributes(), options) - marker = @markBufferRange(bufferRange, options) - @addSelection(marker, options) + @markBufferRange(bufferRange, _.defaults(@getSelectionMarkerAttributes(), options)) + @getLastSelection() # Given a buffer range, this removes all previous selections and creates a new selection for it. # @@ -1314,6 +1312,13 @@ class EditSession @unfoldAll() @trigger 'grammar-changed' + handleMarkerCreation: (marker) => + if marker.matchesAttributes(@getSelectionMarkerAttributes()) + @addSelection(marker) + + getSelectionMarkerAttributes: -> + type: 'selection', editSessionId: @id, invalidation: 'never' + getDebugSnapshot: -> [ @displayBuffer.getDebugSnapshot()