From b1ab0735c7ae3e108de4cb5f6cb49b6acade08d0 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 19 Apr 2012 17:39:59 -0700 Subject: [PATCH 1/6] Add ability to simulate DOM attachment to spec helper --- spec/spec-helper.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 3038816b1..1e126047d 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -131,3 +131,5 @@ $.fn.textInput = (data) -> event = jQuery.event.fix(event) $(this).trigger(event) +$.fn.simulateDomAttachment = -> + $('').append(this) \ No newline at end of file From 800f16bb2965cafdb1c5ea5eaccc14964e2e0c1e Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Thu, 19 Apr 2012 17:55:41 -0700 Subject: [PATCH 2/6] Editor emits an editor-open event when attached --- spec/app/editor-spec.coffee | 11 +++++++++++ src/app/editor.coffee | 1 + 2 files changed, 12 insertions(+) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index 6b30ac670..e4c47638b 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -51,6 +51,17 @@ describe "Editor", -> expect(newEditor.editSessions[0]).toEqual(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", -> 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 a793275f7..5f28b5d78 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -206,6 +206,7 @@ class Editor extends View @hiddenInput.width(@charWidth) @setMaxLineLength() if @softWrap @focus() if @isFocused + @trigger 'editor-open', [this] rootView: -> @parents('#root-view').view() From eaf7ee8ec1a4104f60c75f94ce5122a2b16e5dcb Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 19 Apr 2012 18:12:55 -0700 Subject: [PATCH 3/6] 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 From 56a55299bee3ff769aa63b613dacb6acd1fdbbab Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 19 Apr 2012 18:13:05 -0700 Subject: [PATCH 4/6] :lipstick: --- src/app/window.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/window.coffee b/src/app/window.coffee index 44afa68f1..d7295d15d 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -21,8 +21,8 @@ windowAdditions = $(document).on 'keydown', @_handleKeyEvent startup: (path) -> - @attachRootView(path) @loadUserConfiguration() + @attachRootView(path) $(window).on 'close', => @close() $(window).on 'beforeunload', => @shutdown() @@ -53,7 +53,7 @@ windowAdditions = try require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath) catch error - console.error "Failed to load `#{atom.userConfigurationPath}`", error + console.error "Failed to load `#{atom.userConfigurationPath}`", error.message, error @showConsole() requireStylesheet: (path) -> From 01865e07fd44d1417cb619235ba5a5ef77a4c667 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 20 Apr 2012 08:41:56 -0700 Subject: [PATCH 5/6] Remove autocomplate:toggle, replace with autocomplete:attach and autocomplete:cancel --- spec/app/autocomplete-spec.coffee | 9 ++------- src/app/autocomplete.coffee | 3 +-- src/app/keymaps/autocomplete.coffee | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/spec/app/autocomplete-spec.coffee b/spec/app/autocomplete-spec.coffee index 19f15ab6b..38a7b88d1 100644 --- a/spec/app/autocomplete-spec.coffee +++ b/spec/app/autocomplete-spec.coffee @@ -17,20 +17,15 @@ describe "Autocomplete", -> afterEach -> autocomplete.remove() - describe 'autocomplete:toggle event', -> + describe 'autocomplete:show event', -> it "shows autocomplete view and focuses its mini-editor", -> expect($(document).find('#autocomplete')).not.toExist() - editor.trigger "autocomplete:toggle" + editor.trigger "autocomplete:attach" expect($(document).find('#autocomplete')).toExist() expect(autocomplete.editor.isFocused).toBeFalsy() expect(autocomplete.miniEditor.isFocused).toBeTruthy() - miniEditor.trigger "autocomplete:toggle" - expect($(document).find('#autocomplete')).not.toExist() - expect(autocomplete.editor.isFocused).toBeTruthy() - expect(autocomplete.miniEditor.isFocused).toBeFalsy() - describe "when no text is selected", -> it 'autocompletes word when there is only a prefix', -> editor.buffer.insert([10,0] ,"extra:s:extra") diff --git a/src/app/autocomplete.coffee b/src/app/autocomplete.coffee index 4d1b541c8..54921406b 100644 --- a/src/app/autocomplete.coffee +++ b/src/app/autocomplete.coffee @@ -33,8 +33,7 @@ class Autocomplete extends View @editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer) @editor.on 'before-remove', => @currentBuffer?.off '.autocomplete' - @editor.on 'autocomplete:toggle', => @attach() - @on 'autocomplete:toggle', => @detach() + @editor.on 'autocomplete:attach', => @attach() @on 'autocomplete:confirm', => @confirm() @on 'autocomplete:cancel', => @cancel() diff --git a/src/app/keymaps/autocomplete.coffee b/src/app/keymaps/autocomplete.coffee index 329924173..6ff9cc724 100644 --- a/src/app/keymaps/autocomplete.coffee +++ b/src/app/keymaps/autocomplete.coffee @@ -1,5 +1,5 @@ window.keymap.bindKeys '.editor', - 'escape': 'autocomplete:toggle' + 'escape': 'autocomplete:attach' window.keymap.bindKeys '#autocomplete .editor', 'enter': 'autocomplete:confirm' From 82864d683afcd680fbf99dc0c3cda24a4e6f3107 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Fri, 20 Apr 2012 09:23:19 -0700 Subject: [PATCH 6/6] Removing text from Autocomplete's mini-editor refilters match list --- spec/app/autocomplete-spec.coffee | 14 +++++++++++++- src/app/autocomplete.coffee | 14 ++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/spec/app/autocomplete-spec.coffee b/spec/app/autocomplete-spec.coffee index 38a7b88d1..fd793bd82 100644 --- a/spec/app/autocomplete-spec.coffee +++ b/spec/app/autocomplete-spec.coffee @@ -166,7 +166,19 @@ describe "Autocomplete", -> expect(autocomplete.find('li:eq(0)')).toHaveClass('selected') expect(autocomplete.find('li:eq(1)')).not.toHaveClass('selected') - describe "when the mini-editor receives text input", -> + describe "when the mini-editor's buffer changes", -> + describe "when text is removed from the mini-editor", -> + it "reloads the match list based on the mini-editor's text", -> + editor.buffer.insert([10,0] ,"t") + editor.setCursorBufferPosition([10,0]) + autocomplete.attach() + + expect(autocomplete.matchesList.find('li').length).toBe 8 + miniEditor.textInput('c') + expect(autocomplete.matchesList.find('li').length).toBe 3 + miniEditor.backspace() + expect(autocomplete.matchesList.find('li').length).toBe 8 + describe "when the text contains only word characters", -> it "narrows the list of completions with the fuzzy match algorithm", -> editor.buffer.insert([10,0] ,"t") diff --git a/src/app/autocomplete.coffee b/src/app/autocomplete.coffee index 54921406b..e2839c8f8 100644 --- a/src/app/autocomplete.coffee +++ b/src/app/autocomplete.coffee @@ -37,8 +37,9 @@ class Autocomplete extends View @on 'autocomplete:confirm', => @confirm() @on 'autocomplete:cancel', => @cancel() - @miniEditor.buffer.on 'change', => - @filterMatchList() if @parent()[0] + @miniEditor.buffer.on 'change', (e) => + return unless @parent()[0] + @filterMatchList() @miniEditor.preempt 'move-up', => @selectPreviousMatch() @@ -121,13 +122,14 @@ class Autocomplete extends View if (prefix.length + suffix.length) > 0 currentWord = prefix + @editor.getSelectedText() + suffix - @matches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord) + @baseMatches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord) else - @matches = [] - @renderMatchList() + @baseMatches = [] + + @filterMatchList() filterMatchList: -> - @matches = fuzzyFilter(@matches, @miniEditor.buffer.getText(), key: 'word') + @matches = fuzzyFilter(@baseMatches, @miniEditor.getText(), key: 'word') @renderMatchList() renderMatchList: ->