Bug 1419088 - Hitting the Esc key on the console when sidebar is open should close it. r=bgrins
authorMike Park <mikeparkms@gmail.com>
Tue, 19 Dec 2017 10:54:57 -0500
changeset 397721 40ee4c5df6dd4658e4cd33a4541530404ef7296c
parent 397720 f515861a05f4f9c2c49a4b2c18a80d31b5d0ce72
child 397722 ebc3edf752a800d52672998a00b98595ce45ca1f
push id33190
push userapavel@mozilla.com
push dateThu, 04 Jan 2018 21:27:29 +0000
treeherdermozilla-central@95704f0aec0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1419088
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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