diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 3c467ec4f..3e9ec8fa1 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -109,38 +109,39 @@ describe "RootView", -> expect(rootView.find('.pane').children().length).toBe 0 describe "focus", -> - describe "when there is an active editor", -> - it "hands off focus to the active editor", -> - rootView.attachToDom() - - rootView.open() # create an editor - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.getActiveEditor().isFocused).toBeTruthy() - + describe "when there is an active view", -> + it "hands off focus to the active view", -> + editor = rootView.getActiveView() + editor.isFocused = false rootView.focus() - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.getActiveEditor().isFocused).toBeTruthy() + expect(editor.isFocused).toBeTruthy() - describe "when there is no active editor", -> + describe "when there is no active view", -> beforeEach -> - rootView.getActiveEditor().remove() + rootView.getActivePane().remove() + expect(rootView.getActiveView()).toBeUndefined() rootView.attachToDom() + expect(document.activeElement).toBe document.body describe "when are visible focusable elements (with a -1 tabindex)", -> it "passes focus to the first focusable element", -> - rootView.horizontal.append $$ -> - @div "One", id: 'one', tabindex: -1 - @div "Two", id: 'two', tabindex: -1 + focusable1 = $$ -> @div "One", id: 'one', tabindex: -1 + focusable2 = $$ -> @div "Two", id: 'two', tabindex: -1 + rootView.horizontal.append(focusable1, focusable2) + expect(document.activeElement).toBe document.body rootView.focus() - expect(rootView).not.toMatchSelector(':focus') - expect(rootView.find('#one')).toMatchSelector(':focus') - expect(rootView.find('#two')).not.toMatchSelector(':focus') + expect(document.activeElement).toBe focusable1[0] describe "when there are no visible focusable elements", -> it "surrenders focus to the body", -> - expect(document.activeElement).toBe $('body')[0] + focusable = $$ -> @div "One", id: 'one', tabindex: -1 + rootView.horizontal.append(focusable) + focusable.hide() + expect(document.activeElement).toBe document.body + rootView.focus() + expect(document.activeElement).toBe document.body describe "keymap wiring", -> commandHandler = null diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index cc0682e93..371f49fa8 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -49,7 +49,6 @@ class RootView extends View fontSize = config.get "editor.fontSize" config.set("editor.fontSize", fontSize - 1) if fontSize > 1 - @command 'window:focus-next-pane', => @focusNextPane() @command 'window:save-all', => @saveAll() @command 'window:toggle-invisibles', => @@ -150,16 +149,9 @@ class RootView extends View getActivePane: -> @panes.getActivePane() - getActiveEditor: -> - if (editor = @panes.find('.editor.active')).length - editor.view() - else - @panes.find('.editor:first').view() getActivePaneItem: -> @panes.getActivePaneItem() - getActiveEditSession: -> - @getActiveEditor()?.activeEditSession getActiveView: -> @panes.getActiveView()