From 575e34d5e49b199d05b4d28f2f54f5b8ab5173d5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 27 Dec 2012 21:53:43 -0800 Subject: [PATCH] Forward window focus when active element is body This problem was when the focus element is detached when navigating away from the window and when the window is then given focus again nothing has focus. The solution is to use RootView's focus handler on the window to bring focus to the editor or other view when the document's active element is the body meaning nothing inside the RootView currently has focus. --- src/app/root-view.coffee | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 957ec6713..059c983df 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -55,20 +55,24 @@ class RootView extends View panesViewState: @panes.children().view()?.serialize() extensionStates: @serializeExtensions() - handleEvents: -> - @on 'toggle-dev-tools', => atom.toggleDevTools() - @on 'focus', (e) => - if @getActiveEditor() - @getActiveEditor().focus() + handleFocus: (e) -> + if @getActiveEditor() + @getActiveEditor().focus() + false + else + @setTitle(null) + focusableChild = this.find("[tabindex=-1]:visible:first") + if focusableChild.length + focusableChild.focus() false else - @setTitle(null) - focusableChild = this.find("[tabindex=-1]:visible:first") - if focusableChild.length - focusableChild.focus() - false - else - true + true + + handleEvents: -> + @on 'toggle-dev-tools', => atom.toggleDevTools() + @on 'focus', (e) => @handleFocus(e) + $(window).on 'focus', (e) => + @handleFocus(e) if document.activeElement is document.body @on 'active-editor-path-change', (e, path) => @project.setPath(path) unless @project.getRootDirectory()