Serialize EditSession's buffer's id instead of its path

This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-07-02 17:29:23 -07:00
committed by Kevin Sawicki
parent 9b22ca4825
commit e82170efcb
3 changed files with 14 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ class EditSession
### Internal ###
@version: 2
@version: 3
@deserialize: (state) ->
new EditSession(state)
@@ -38,7 +38,7 @@ class EditSession
project.editSessions.push(this)
@state = optionsOrState
{tabLength, softTabs, @softWrap} = @state.toObject()
@buffer = project.bufferForPath(@state.get('bufferPath'))
@buffer = project.bufferForId(@state.get('bufferId'))
@setScrollTop(@state.get('scrollTop'))
@setScrollLeft(@state.get('scrollLeft'))
cursorScreenPosition = @state.getObject('cursorScreenPosition')
@@ -98,7 +98,7 @@ class EditSession
serialize: ->
@state.set
bufferPath: @buffer.getPath()
bufferId: @buffer.id
scrollTop: @getScrollTop()
scrollLeft: @getScrollLeft()
tabLength: @getTabLength()

View File

@@ -232,6 +232,9 @@ class Project
else
@buildBuffer(null, text)
bufferForId: (id) ->
_.find @buffers, (buffer) -> buffer.id is id
# Given a file path, this sets its {Buffer}.
#
# filePath - A {String} representing a path

View File

@@ -7,6 +7,7 @@ EventEmitter = require 'event-emitter'
UndoManager = require 'undo-manager'
BufferChangeOperation = require 'buffer-change-operation'
BufferMarker = require 'buffer-marker'
guid = require 'guid'
# Public: Represents the contents of a file.
#
@@ -15,8 +16,7 @@ BufferMarker = require 'buffer-marker'
module.exports =
class TextBuffer
@acceptsDocuments: true
@version: 1
@idCounter: 1
@version: 2
registerDeserializer(this)
@deserialize: (state) ->
@@ -38,7 +38,6 @@ class TextBuffer
# path - A {String} representing the file path
# initialText - A {String} setting the starting text
constructor: (args...) ->
@id = @constructor.idCounter++
@nextMarkerId = 1
@validMarkers = {}
@invalidMarkers = {}
@@ -47,10 +46,15 @@ class TextBuffer
@state = args[0]
@text = @state.get('text')
path = @state.get('path')
@id = @state.get('id')
else
[path, initialText] = args
@text = telepath.Document.create(initialText, shareStrings: true) if initialText
@state = telepath.Document.create(deserializer: @constructor.name, version: @constructor.version)
@id = guid.create().toString()
@state = telepath.Document.create
id: @id
deserializer: @constructor.name
version: @constructor.version
if path
@setPath(path)