Bug 1453894 - Give focus to console input when closing sidebar with Escape key; r=Honza. draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Mon, 16 Apr 2018 10:23:39 +0200
changeset 782481 47b3c832cbadde8968527f17aa477148f3fa451a
parent 782432 7ff499dfcd51cf4a95ebf0db506b415bf7bb27c3
push id106553
push userbmo:nchevobbe@mozilla.com
push dateMon, 16 Apr 2018 08:24:39 +0000
reviewersHonza
bugs1453894
milestone61.0a1
Bug 1453894 - Give focus to console input when closing sidebar with Escape key; r=Honza. MozReview-Commit-ID: J9y6XkmKJ43
devtools/client/webconsole/new-webconsole.js
devtools/client/webconsole/test/mochitest/browser_webconsole_close_sidebar.js
--- a/devtools/client/webconsole/new-webconsole.js
+++ b/devtools/client/webconsole/new-webconsole.js
@@ -250,16 +250,17 @@ NewWebConsoleFrame.prototype = {
         Services.scriptloader.loadSubScript(
           "chrome://browser/content/browser-development-helpers.js", this.window);
         shortcuts.on("CmdOrCtrl+Alt+R", this.window.DevelopmentHelpers.quickRestart);
       }
     } else if (Services.prefs.getBoolPref(PREF_SIDEBAR_ENABLED)) {
       shortcuts.on("Esc", event => {
         if (!this.jsterm.autocompletePopup || !this.jsterm.autocompletePopup.isOpen) {
           this.newConsoleOutput.dispatchSidebarClose();
+          this.jsterm.focus();
         }
       });
     }
   },
   /**
    * Handler for page location changes.
    *
    * @param string uri
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_close_sidebar.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_close_sidebar.js
@@ -64,16 +64,18 @@ add_task(async function() {
   await showSidebar(hud);
 
   info("Send escape to hide sidebar");
   onSidebarShown = waitForNodeMutation(wrapper, { childList: true });
   EventUtils.synthesizeKey("KEY_Escape");
   await onSidebarShown;
   sidebar = hud.ui.document.querySelector(".sidebar");
   ok(!sidebar, "Sidebar hidden after sending esc");
+  let inputNode = hud.jsterm.inputNode;
+  ok(hasFocus(inputNode), "console input is focused after closing the sidebar");
 });
 
 async function showSidebar(hud) {
   let onMessage = waitForMessage(hud, "Object");
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function() {
     content.wrappedJSObject.console.log({a: 1});
   });
   await onMessage;