Editor emits an editor-open event when attached

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-04-19 17:55:41 -07:00 committed by Corey Johnson
parent b1ab0735c7
commit 800f16bb29
2 changed files with 12 additions and 0 deletions

View File

@ -51,6 +51,17 @@ describe "Editor", ->
expect(newEditor.editSessions[0]).toEqual(editor.editSessions[0]) expect(newEditor.editSessions[0]).toEqual(editor.editSessions[0])
expect(newEditor.editSessions[0]).not.toBe(editor.editSessions[0]) expect(newEditor.editSessions[0]).not.toBe(editor.editSessions[0])
describe "editor-open event", ->
it 'triggers an editor-open event when it is added to the DOM', ->
openHandler = jasmine.createSpy('openHandler')
editor.on 'editor-open', openHandler
editor.simulateDomAttachment()
expect(openHandler).toHaveBeenCalled()
[event, eventEditor] = openHandler.argsForCall[0]
expect(eventEditor).toBe editor
describe "text rendering", -> describe "text rendering", ->
it "creates a line element for each line in the buffer with the html-escaped text of the line", -> it "creates a line element for each line in the buffer with the html-escaped text of the line", ->
expect(editor.lines.find('.line').length).toEqual(buffer.numLines()) expect(editor.lines.find('.line').length).toEqual(buffer.numLines())

View File

@ -206,6 +206,7 @@ class Editor extends View
@hiddenInput.width(@charWidth) @hiddenInput.width(@charWidth)
@setMaxLineLength() if @softWrap @setMaxLineLength() if @softWrap
@focus() if @isFocused @focus() if @isFocused
@trigger 'editor-open', [this]
rootView: -> rootView: ->
@parents('#root-view').view() @parents('#root-view').view()