Bug 1532939 - Add Cmd + K support to clear the console on OSX. r=nchevobbe.
authorHelena Moreno <helenaenred@gmail.com>
Tue, 12 Mar 2019 06:21:07 +0000
changeset 521492 f3448180f267
parent 521491 2429f6898afa
child 521493 7196b821847c
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1532939
milestone67.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 1532939 - Add Cmd + K support to clear the console on OSX. r=nchevobbe. This is a common shortcut on OSX to clear terminal output, and something that Chrome does, so it makes sense to implement it in our console as well. Differential Revision: https://phabricator.services.mozilla.com/D22657
devtools/client/locales/en-US/webconsole.properties
devtools/client/webconsole/test/mochitest/browser_webconsole_keyboard_accessibility.js
devtools/client/webconsole/webconsole-ui.js
--- a/devtools/client/locales/en-US/webconsole.properties
+++ b/devtools/client/locales/en-US/webconsole.properties
@@ -138,16 +138,17 @@ webconsole.find.key=CmdOrCtrl+F
 # LOCALIZATION NOTE (webconsole.close.key)
 # Key shortcut used to close the Browser console (doesn't work in regular web console)
 webconsole.close.key=CmdOrCtrl+W
 
 # LOCALIZATION NOTE (webconsole.clear.key*)
 # Key shortcut used to clear the console output
 webconsole.clear.key=Ctrl+Shift+L
 webconsole.clear.keyOSX=Ctrl+L
+webconsole.clear.alternativeKeyOSX=Cmd+K
 
 # LOCALIZATION NOTE (webconsole.menu.copyURL.label)
 # Label used for a context-menu item displayed for network message logs. Clicking on it
 # copies the URL displayed in the message to the clipboard.
 webconsole.menu.copyURL.label=Copy Link Location
 webconsole.menu.copyURL.accesskey=a
 
 # LOCALIZATION NOTE (webconsole.menu.openURL.label)
--- a/devtools/client/webconsole/test/mochitest/browser_webconsole_keyboard_accessibility.js
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_keyboard_accessibility.js
@@ -59,17 +59,32 @@ async function performTests() {
   let clearShortcut;
   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);
-  ok(isInputFocused(hud), "input is focused");
+  ok(isInputFocused(hud), "console was cleared and input is focused");
+
+  if (Services.appinfo.OS === "Darwin") {
+    info("Log a new message from the content page");
+    const onMessage = waitForMessage(hud, "another simple text message");
+    ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() {
+      content.console.log("another simple text message");
+    });
+    await onMessage;
+
+    info("Send Cmd-K to clear console");
+    synthesizeKeyShortcut(WCUL10n.getStr("webconsole.clear.alternativeKeyOSX"));
+
+    await waitFor(() => findMessages(hud, "").length == 0);
+    ok(isInputFocused(hud), "console was cleared as expected with alternative shortcut");
+  }
 
   // Focus filter
   info("try ctrl-f to focus filter");
   synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
   ok(!isInputFocused(hud), "input is not focused");
   ok(hasFocus(hud.ui.filterBox), "filter input is focused");
 
   info("try ctrl-f when filter is already focused");
--- a/devtools/client/webconsole/webconsole-ui.js
+++ b/devtools/client/webconsole/webconsole-ui.js
@@ -111,18 +111,23 @@ class WebConsoleUI {
   /**
    * Clear the Web Console output.
    *
    * This method emits the "messages-cleared" notification.
    *
    * @param boolean clearStorage
    *        True if you want to clear the console messages storage associated to
    *        this Web Console.
+   * @param object event
+   *        If the event exists, calls preventDefault on it.
    */
-  clearOutput(clearStorage) {
+  clearOutput(clearStorage, event) {
+    if (event) {
+      event.preventDefault();
+    }
     if (this.wrapper) {
       this.wrapper.dispatchMessagesClear();
     }
     this.webConsoleClient.clearNetworkRequests();
     if (clearStorage) {
       this.webConsoleClient.clearMessagesCache();
     }
     this.emit("messages-cleared");
@@ -257,22 +262,24 @@ class WebConsoleUI {
     shortcuts.on(l10n.getStr("webconsole.find.key"),
                  event => {
                    this.filterBox.focus();
                    event.preventDefault();
                  });
 
     let clearShortcut;
     if (AppConstants.platform === "macosx") {
+      const alternativaClearShortcut = l10n.getStr("webconsole.clear.alternativeKeyOSX");
+      shortcuts.on(alternativaClearShortcut, event => this.clearOutput(true, event));
       clearShortcut = l10n.getStr("webconsole.clear.keyOSX");
     } else {
       clearShortcut = l10n.getStr("webconsole.clear.key");
     }
 
-    shortcuts.on(clearShortcut, () => this.clearOutput(true));
+    shortcuts.on(clearShortcut, event => this.clearOutput(true, event));
 
     if (this.isBrowserConsole) {
       // Make sure keyboard shortcuts work immediately after opening
       // the Browser Console (Bug 1461366).
       this.window.focus();
 
       shortcuts.on(l10n.getStr("webconsole.close.key"),
                    this.window.top.close.bind(this.window.top));