Fire edit-session-created event when deserializing

This event was previously not being fired when splitting panes
since the constructor pushing the edit session directly to the
project's array.

Closes #684
This commit is contained in:
Kevin Sawicki 2013-08-06 19:05:24 -07:00
parent 7d58008ed3
commit 633306e6bf
4 changed files with 23 additions and 3 deletions

View File

@ -1,3 +1,4 @@
* Fixed: Wrap in quotes/parens now works in split panes
* Improved: Autocomplete now includes CSS property names and values
* Improved: Settings GUI is now a pane item
* Added: Support package filtering in Settings GUI

View File

@ -31,6 +31,22 @@ describe "Project", ->
expect(project.getPath()).toBe '/tmp'
fsUtils.remove('/tmp/atom-test-save-sets-project-path')
describe "when an edit session is deserialized", ->
it "emits an 'edit-session-created' event and stores the edit session", ->
handler = jasmine.createSpy('editSessionCreatedHandler')
project.on 'edit-session-created', handler
editSession1 = project.open("a")
expect(handler.callCount).toBe 1
expect(project.getEditSessions().length).toBe 1
expect(project.getEditSessions()[0]).toBe editSession1
editSession2 = deserialize(editSession1.serialize())
expect(handler.callCount).toBe 2
expect(project.getEditSessions().length).toBe 2
expect(project.getEditSessions()[0]).toBe editSession1
expect(project.getEditSessions()[1]).toBe editSession2
describe ".open(path)", ->
[fooOpener, barOpener, absolutePath, newBufferHandler, newEditSessionHandler] = []
beforeEach ->

View File

@ -36,13 +36,13 @@ class EditSession
constructor: (optionsOrState) ->
if optionsOrState instanceof telepath.Document
project.editSessions.push(this)
@state = optionsOrState
{tabLength, softTabs, @softWrap} = @state.toObject()
@buffer = deserialize(@state.get('buffer'))
@setScrollTop(@state.get('scrollTop'))
@setScrollLeft(@state.get('scrollLeft'))
cursorScreenPosition = @state.getObject('cursorScreenPosition')
project.addEditSession(this)
else
{@buffer, tabLength, softTabs, @softWrap} = optionsOrState
@state = telepath.Document.create

View File

@ -179,6 +179,10 @@ class Project
getEditSessions: ->
new Array(@editSessions...)
addEditSession: (editSession) ->
@editSessions.push editSession
@trigger 'edit-session-created', editSession
### Public ###
# Removes an {EditSession} association from the project.
@ -297,8 +301,7 @@ class Project
options = _.extend(@defaultEditSessionOptions(), editSessionOptions)
options.buffer = buffer
editSession = new EditSession(options)
@editSessions.push editSession
@trigger 'edit-session-created', editSession
@addEditSession(editSession)
editSession
defaultEditSessionOptions: ->