From a724ef3b4017430f6c92a1e00f2c7747e130fa52 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 17 Jul 2013 15:29:21 -0700 Subject: [PATCH] Tag selection markers with a disambiguating EditSession id This prevents selection markers created by different edit sessions from being shared. Otherwise every edit session for a buffer would be forced to have the same selection/cursor state. --- spec/app/edit-session-spec.coffee | 6 ++++++ src/app/edit-session.coffee | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 57684f6b3..d16d7f7fa 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -946,6 +946,12 @@ describe "EditSession", -> editSession.setCursorScreenPosition([3, 3]) expect(selection.isEmpty()).toBeTruthy() + it "does not share selections between different edit sessions for the same buffer", -> + editSession2 = project.open('sample.js') + editSession.setSelectedBufferRanges([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) + editSession2.setSelectedBufferRanges([[[8, 7], [6, 5]], [[4, 3], [2, 1]]]) + expect(editSession2.getSelectedBufferRanges()).not.toEqual editSession.getSelectedBufferRanges() + describe "buffer manipulation", -> describe ".insertText(text)", -> describe "when there are multiple empty selections", -> diff --git a/src/app/edit-session.coffee b/src/app/edit-session.coffee index 4fb137ba9..a30342869 100644 --- a/src/app/edit-session.coffee +++ b/src/app/edit-session.coffee @@ -2,6 +2,7 @@ _ = require 'underscore' fsUtils = require 'fs-utils' path = require 'path' telepath = require 'telepath' +guid = require 'guid' {Point, Range} = telepath Buffer = require 'text-buffer' LanguageMode = require 'language-mode' @@ -26,6 +27,7 @@ class EditSession @deserialize: (state) -> new EditSession(state) + id: null languageMode: null displayBuffer: null cursors: null @@ -40,7 +42,7 @@ class EditSession if optionsOrState instanceof telepath.Document project.editSessions.push(this) @state = optionsOrState - {tabLength, softTabs, @softWrap} = @state.toObject() + {@id, tabLength, softTabs, @softWrap} = @state.toObject() @setBuffer(project.bufferForId(@state.get('bufferId'))) @buildDisplayBuffer({tabLength}) @addSelection(marker) for marker in @findMarkers(@getSelectionMarkerAttributes()) @@ -48,9 +50,11 @@ class EditSession @setScrollLeft(@state.get('scrollLeft')) else {buffer, tabLength, softTabs, @softWrap} = optionsOrState + @id = guid.create().toString() @state = telepath.Document.create deserializer: 'EditSession' version: @constructor.version + id: @id scrollTop: 0 scrollLeft: 0 @setBuffer(buffer)