Merge branch 'master' into dh-async-repo

This commit is contained in:
joshaber
2015-12-09 15:44:45 -05:00
8 changed files with 58 additions and 21 deletions

View File

@@ -308,12 +308,20 @@ class Project extends Model
findBufferForPath: (filePath) ->
_.find @buffers, (buffer) -> buffer.getPath() is filePath
findBufferForId: (id) ->
_.find @buffers, (buffer) -> buffer.getId() is id
# Only to be used in specs
bufferForPathSync: (filePath) ->
absoluteFilePath = @resolvePath(filePath)
existingBuffer = @findBufferForPath(absoluteFilePath) if filePath
existingBuffer ? @buildBufferSync(absoluteFilePath)
# Only to be used when deserializing
bufferForIdSync: (id) ->
existingBuffer = @findBufferForId(id) if id
existingBuffer ? @buildBufferSync()
# Given a file path, this retrieves or creates a new {TextBuffer}.
#
# If the `filePath` already has a `buffer`, that value is used instead. Otherwise,
@@ -329,9 +337,6 @@ class Project extends Model
else
@buildBuffer(absoluteFilePath)
bufferForId: (id) ->
_.find @buffers, (buffer) -> buffer.id is id
# Still needed when deserializing a tokenized buffer
buildBufferSync: (absoluteFilePath) ->
buffer = new TextBuffer({filePath: absoluteFilePath})

View File

@@ -677,7 +677,7 @@ class TextEditor extends Model
# this editor.
shouldPromptToSave: ({windowCloseRequested}={}) ->
if windowCloseRequested
@isModified()
false
else
@isModified() and not @buffer.hasMultipleEditors()

View File

@@ -22,7 +22,11 @@ class TokenizedBuffer extends Model
changeCount: 0
@deserialize: (state, atomEnvironment) ->
state.buffer = atomEnvironment.project.bufferForPathSync(state.bufferPath)
if state.bufferId
state.buffer = atomEnvironment.project.bufferForIdSync(state.bufferId)
else
# TODO: remove this fallback after everyone transitions to the latest version.
state.buffer = atomEnvironment.project.bufferForPathSync(state.bufferPath)
state.config = atomEnvironment.config
state.grammarRegistry = atomEnvironment.grammars
state.packageManager = atomEnvironment.packages
@@ -53,6 +57,7 @@ class TokenizedBuffer extends Model
serialize: ->
deserializer: 'TokenizedBuffer'
bufferPath: @buffer.getPath()
bufferId: @buffer.getId()
tabLength: @tabLength
ignoreInvisibles: @ignoreInvisibles
largeFileMode: @largeFileMode