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.
This commit is contained in:
Nathan Sobo 2013-07-17 15:29:21 -07:00
parent ab8c0bbf04
commit a724ef3b40
2 changed files with 11 additions and 1 deletions

View File

@ -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", ->

View File

@ -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)