Projects w/ EditSessions for now-deleted files can now be reloaded w/out error

This commit is contained in:
Nathan Sobo 2012-09-18 13:30:16 -06:00
parent 68effe3303
commit 7937380eed
3 changed files with 19 additions and 3 deletions

View File

@ -74,6 +74,14 @@ describe "Editor", ->
expect(newEditor.scrollTop()).toBe editor.scrollTop()
expect(newEditor.scrollView.scrollLeft()).toBe 44
it "does not blow up if no file exists for a previous edit session, but prints a warning", ->
spyOn(console, 'warn')
fs.write('/tmp/delete-me')
editor.edit(rootView.project.buildEditSessionForPath('/tmp/delete-me'))
fs.remove('/tmp/delete-me')
newEditor = editor.copy()
expect(console.warn).toHaveBeenCalled()
describe "when the editor is attached to the dom", ->
it "calculates line height and char width and updates the pixel position of the cursor", ->
expect(editor.lineHeight).toBeNull()

View File

@ -9,13 +9,18 @@ EventEmitter = require 'event-emitter'
Range = require 'range'
AnchorRange = require 'anchor-range'
_ = require 'underscore'
fs = require 'fs'
module.exports =
class EditSession
@idCounter: 1
@deserialize: (state, project) ->
session = project.buildEditSessionForPath(state.buffer)
if fs.exists(state.buffer)
session = project.buildEditSessionForPath(state.buffer)
else
console.warn "Could not build edit session for path '#{state.buffer}' because that file no longer exists"
session = project.buildEditSessionForPath(null)
session.setScrollTop(state.scrollTop)
session.setScrollLeft(state.scrollLeft)
session.setCursorScreenPosition(state.cursorScreenPosition)

View File

@ -119,8 +119,11 @@ class Project
bufferForPath: (filePath) ->
if filePath?
filePath = @resolve(filePath)
buffer = _.find @buffers, (buffer) -> buffer.getPath() == filePath
buffer or @buildBuffer(filePath)
if filePath
buffer = _.find @buffers, (buffer) -> buffer.getPath() == filePath
buffer or @buildBuffer(filePath)
else
else
@buildBuffer()