Bug 1419088 - Hitting the Esc key on the console when sidebar is open should close it. r=bgrins draft
authorMike Park <mikeparkms@gmail.com>
Tue, 19 Dec 2017 10:54:57 -0500
changeset 713207 6ef5fa411fbe512cbe6c7b055ba3efde938559af
parent 712776 390394ae47a3ac39c18357a0146a659cde657ce0
child 744269 874a465fb23751fc6446d4fed72a66d01586a140
push id93572
push userbmo:mpark@mozilla.com
push dateTue, 19 Dec 2017 20:17:39 +0000
reviewersbgrins
bugs1419088
milestone59.0a1
Bug 1419088 - Hitting the Esc key on the console when sidebar is open should close it. r=bgrins MozReview-Commit-ID: DqHjv0tXdTW
devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
devtools/client/webconsole/new-console-output/reducers/ui.js
devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_close_sidebar.js
devtools/client/webconsole/new-webconsole.js
--- a/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
+++ b/devtools/client/webconsole/new-console-output/new-console-output-wrapper.js
@@ -277,16 +277,20 @@ NewConsoleOutputWrapper.prototype = {
       this.batchedMessageUpdates({ res, message });
     }
   },
 
   dispatchRequestUpdate: function (id, data) {
     this.batchedRequestUpdates({ id, data });
   },
 
+  dispatchSidebarClose: function () {
+    store.dispatch(actions.sidebarClose());
+  },
+
   batchedMessageUpdates: function (info) {
     this.queuedMessageUpdates.push(info);
     this.setTimeoutIfNeeded();
   },
 
   batchedRequestUpdates: function (message) {
     this.queuedRequestUpdates.push(message);
     this.setTimeoutIfNeeded();
--- a/devtools/client/webconsole/new-console-output/reducers/ui.js
+++ b/devtools/client/webconsole/new-console-output/reducers/ui.js
@@ -37,17 +37,17 @@ function ui(state = UiState(), action) {
     case PERSIST_TOGGLE:
       return Object.assign({}, state, {persistLogs: !state.persistLogs});
     case TIMESTAMPS_TOGGLE:
       return Object.assign({}, state, {timestampsVisible: action.visible});
     case SELECT_NETWORK_MESSAGE_TAB:
       return Object.assign({}, state, {networkMessageActiveTabId: action.id});
     case SIDEBAR_CLOSE:
       return Object.assign({}, state, {
-        sidebarVisible: !state.sidebarVisible,
+        sidebarVisible: false,
         gripInSidebar: null
       });
     case INITIALIZE:
       return Object.assign({}, state, {initialized: true});
     case MESSAGES_CLEAR:
       return Object.assign({}, state, {sidebarVisible: false, gripInSidebar: null});
     case SHOW_OBJECT_IN_SIDEBAR:
       if (action.grip === state.gripInSidebar) {
--- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_close_sidebar.js
+++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_close_sidebar.js
@@ -43,28 +43,37 @@ add_task(async function () {
   if (Services.appinfo.OS === "Darwin") {
     clearShortcut = WCUL10n.getStr("webconsole.clear.keyOSX");
   } else {
     clearShortcut = WCUL10n.getStr("webconsole.clear.key");
   }
   synthesizeKeyShortcut(clearShortcut);
   await waitFor(() => findMessages(hud, "").length == 0);
   sidebar = hud.ui.document.querySelector(".sidebar");
-  ok(!sidebar, "Sidebar hidden after console.clear()");
+  ok(!sidebar, "Sidebar hidden after ctrl-l");
 
   await showSidebar(hud);
 
   info("Click the close button");
   let closeButton = hud.ui.document.querySelector(".sidebar-close-button");
   let wrapper = hud.ui.document.querySelector(".webconsole-output-wrapper");
   let onSidebarShown = waitForNodeMutation(wrapper, { childList: true });
   closeButton.click();
   await onSidebarShown;
   sidebar = hud.ui.document.querySelector(".sidebar");
   ok(!sidebar, "Sidebar hidden after clicking on close button");
+
+  await showSidebar(hud);
+
+  info("Send escape to hide sidebar");
+  onSidebarShown = waitForNodeMutation(wrapper, { childList: true });
+  EventUtils.synthesizeKey("VK_ESCAPE", {});
+  await onSidebarShown;
+  sidebar = hud.ui.document.querySelector(".sidebar");
+  ok(!sidebar, "Sidebar hidden after sending esc");
 });
 
 async function showSidebar(hud) {
   let onMessage = waitForMessage(hud, "Object");
   ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
     content.wrappedJSObject.console.log({a: 1});
   });
   await onMessage;
--- a/devtools/client/webconsole/new-webconsole.js
+++ b/devtools/client/webconsole/new-webconsole.js
@@ -16,16 +16,17 @@ const { JSTerm } = require("devtools/cli
 const { WebConsoleConnectionProxy } = require("devtools/client/webconsole/webconsole-connection-proxy");
 const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
 const { l10n } = require("devtools/client/webconsole/new-console-output/utils/messages");
 const system = require("devtools/shared/system");
 const { ZoomKeys } = require("devtools/client/shared/zoom-keys");
 
 const PREF_MESSAGE_TIMESTAMP = "devtools.webconsole.timestampMessages";
 const PREF_PERSISTLOG = "devtools.webconsole.persistlog";
+const PREF_SIDEBAR_ENABLED = "devtools.webconsole.sidebarToggle";
 
 // XXX: This file is incomplete (see bug 1326937).
 // It's used when loading the webconsole with devtools-launchpad, but will ultimately be
 // the entry point for the new frontend
 
 /**
  * A WebConsoleFrame instance is an interactive console initialized *per target*
  * that displays console log data as well as provides an interactive terminal to
@@ -247,16 +248,22 @@ NewWebConsoleFrame.prototype = {
 
     shortcuts.on(clearShortcut, () => this.jsterm.clearOutput(true));
 
     if (this.isBrowserConsole) {
       shortcuts.on(l10n.getStr("webconsole.close.key"),
                    this.window.close.bind(this.window));
 
       ZoomKeys.register(this.window);
+    } else if (Services.prefs.getBoolPref(PREF_SIDEBAR_ENABLED)) {
+      shortcuts.on("Esc", (name, event) => {
+        if (!this.jsterm.autocompletePopup || !this.jsterm.autocompletePopup.isOpen) {
+          this.newConsoleOutput.dispatchSidebarClose();
+        }
+      });
     }
   },
   /**
    * Handler for page location changes.
    *
    * @param string uri
    *        New page location.
    * @param string title