Editor subscribes to buffer-path-change events on edit sessions, not buffers directly

This commit is contained in:
Nathan Sobo 2012-07-04 12:05:09 -06:00
parent 3c259224b6
commit fb6aa46531
3 changed files with 4 additions and 26 deletions

View File

@ -91,18 +91,6 @@ describe "Editor", ->
editor.attachToDom()
expect(editor).toMatchSelector ":has(:focus)"
it "unsubscribes from the buffer when it is removed from the dom", ->
editSession = rootView.project.open('sample.txt')
previousSubscriptionCount = editSession.buffer.subscriptionCount()
editor.attachToDom()
editor.edit(editSession)
expect(editSession.buffer.subscriptionCount()).toBeGreaterThan previousSubscriptionCount
expect($('.editor')).toExist()
editor.remove()
expect(editSession.buffer.subscriptionCount()).toBeLessThan previousSubscriptionCount
expect($('.editor')).not.toExist()
describe "when the editor recieves focus", ->
it "focuses the hidden input", ->
editor.attachToDom()
@ -192,18 +180,6 @@ describe "Editor", ->
editor.edit(previousEditSession)
expect(editor.activeEditSession).toBe previousEditSession
it "unsubscribes from the previously assigned buffer", ->
previousEditSession = editor.activeEditSession
previousSubscriptionCount = previousEditSession.buffer.subscriptionCount()
editor.edit(otherEditSession)
expect(previousEditSession.buffer.subscriptionCount()).toBe previousSubscriptionCount - 1
editor.edit(previousEditSession)
expect(previousEditSession.buffer.subscriptionCount()).toBe previousSubscriptionCount
editor.edit(otherEditSession)
expect(previousEditSession.buffer.subscriptionCount()).toBe previousSubscriptionCount - 1
it "handles buffer manipulation correctly after switching to a new edit session", ->
editor.attachToDom()
editor.insertText("abc\n")

View File

@ -41,6 +41,9 @@ class EditSession
@selections = []
@addCursorAtScreenPosition([0, 0])
@buffer.on "path-change.edit-session-#{@id}", =>
@trigger 'buffer-path-change'
@buffer.on "change.edit-session-#{@id}", (e) =>
anchor.handleBufferChange(e) for anchor in @getAnchors()
@mergeCursors()

View File

@ -385,10 +385,9 @@ class Editor extends View
@unsubscribeFromBuffer() if @buffer
@buffer = @activeEditSession.buffer
@buffer.on "path-change.editor#{@id}", => @trigger 'editor-path-change'
@trigger 'editor-path-change'
@activeEditSession.on "buffer-path-change", => @trigger 'editor-path-change'
@renderWhenAttached()
activateEditSessionForPath: (path) ->