From eaf7ee8ec1a4104f60c75f94ce5122a2b16e5dcb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 19 Apr 2012 18:12:55 -0700 Subject: [PATCH] Only emit editor-open event once (on first attachment) --- spec/app/editor-spec.coffee | 7 +++++-- src/app/editor.coffee | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index e4c47638b..d00eb58ec 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -52,16 +52,19 @@ describe "Editor", -> 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', -> + it 'only triggers an editor-open event when it is first 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 + openHandler.reset() + editor.simulateDomAttachment() + expect(openHandler).not.toHaveBeenCalled() + describe "text rendering", -> 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()) diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 5f28b5d78..97af57427 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -201,7 +201,9 @@ class Editor extends View else @gutter.addClass('drop-shadow') - @on 'attach', => + @on 'attach', (e) => + return if @attached + @attached = true @calculateDimensions() @hiddenInput.width(@charWidth) @setMaxLineLength() if @softWrap