Bug 1513707 - [release 108] Allow closing source tabs via keyboard (#7417). r=davidwalsh
authorJason Laster <jlaster@mozilla.com>
Wed, 12 Dec 2018 16:35:16 -0500
changeset 450787 cdf28f0b6d6676ea552cd131168f8d5a4cee1651
parent 450786 e48826dd7a2c44ccd4d332ecece46ac5e0e31cba
child 450788 ccd04cd205edf03809811a9759ad122fb9e4f412
push id35208
push usercsabou@mozilla.com
push dateSat, 15 Dec 2018 02:48:07 +0000
treeherdermozilla-central@d86d184dc7d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdavidwalsh
bugs1513707
milestone66.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 1513707 - [release 108] Allow closing source tabs via keyboard (#7417). r=davidwalsh
devtools/client/debugger/new/src/components/Editor/index.js
devtools/client/debugger/new/test/mochitest/browser.ini
devtools/client/debugger/new/test/mochitest/browser_dbg-tabs-keyboard.js
devtools/client/debugger/new/test/mochitest/browser_dbg-tabs-without-urls.js
devtools/client/debugger/new/test/mochitest/browser_dbg-tabs.js
devtools/client/debugger/new/test/mochitest/helpers.js
devtools/client/locales/en-US/debugger.properties
--- a/devtools/client/debugger/new/src/components/Editor/index.js
+++ b/devtools/client/debugger/new/src/components/Editor/index.js
@@ -89,17 +89,18 @@ export type Props = {
   closeConditionalPanel: void => void,
   setContextMenu: (string, any) => void,
   continueToHere: number => void,
   toggleBreakpoint: number => void,
   toggleBreakpointsAtLine: number => void,
   addOrToggleDisabledBreakpoint: number => void,
   jumpToMappedLocation: any => void,
   traverseResults: (boolean, Object) => void,
-  updateViewport: void => void
+  updateViewport: void => void,
+  closeTab: Source => void
 };
 
 type State = {
   editor: SourceEditor
 };
 
 class Editor extends PureComponent<Props, State> {
   $editorWrapper: ?HTMLDivElement;
@@ -201,33 +202,44 @@ class Editor extends PureComponent<Props
       "sourceSearch.search.againPrev.key2"
     );
 
     shortcuts.on(L10N.getStr("toggleBreakpoint.key"), this.onToggleBreakpoint);
     shortcuts.on(
       L10N.getStr("toggleCondPanel.key"),
       this.onToggleConditionalPanel
     );
+    shortcuts.on(L10N.getStr("sourceTabs.closeTab.key"), this.onClosePress);
     shortcuts.on("Esc", this.onEscape);
     shortcuts.on(searchAgainPrevKey, this.onSearchAgain);
     shortcuts.on(searchAgainKey, this.onSearchAgain);
   }
 
+  onClosePress = (key, e: KeyboardEvent) => {
+    const { selectedSource } = this.props;
+    if (selectedSource) {
+      e.preventDefault();
+      e.stopPropagation();
+      this.props.closeTab(selectedSource);
+    }
+  };
+
   componentWillUnmount() {
     if (this.state.editor) {
       this.state.editor.destroy();
       this.state.editor.codeMirror.off("scroll", this.onEditorScroll);
       this.setState({ editor: null });
     }
 
     const searchAgainKey = L10N.getStr("sourceSearch.search.again.key2");
     const searchAgainPrevKey = L10N.getStr(
       "sourceSearch.search.againPrev.key2"
     );
     const shortcuts = this.context.shortcuts;
+    shortcuts.off(L10N.getStr("sourceTabs.closeTab.key"));
     shortcuts.off(L10N.getStr("toggleBreakpoint.key"));
     shortcuts.off(L10N.getStr("toggleCondPanel.key"));
     shortcuts.off(searchAgainPrevKey);
     shortcuts.off(searchAgainKey);
   }
 
   componentDidUpdate(prevProps, prevState) {
     const { selectedSource } = this.props;
@@ -624,11 +636,12 @@ export default connect(
     closeConditionalPanel: actions.closeConditionalPanel,
     setContextMenu: actions.setContextMenu,
     continueToHere: actions.continueToHere,
     toggleBreakpoint: actions.toggleBreakpoint,
     toggleBreakpointsAtLine: actions.toggleBreakpointsAtLine,
     addOrToggleDisabledBreakpoint: actions.addOrToggleDisabledBreakpoint,
     jumpToMappedLocation: actions.jumpToMappedLocation,
     traverseResults: actions.traverseResults,
-    updateViewport: actions.updateViewport
+    updateViewport: actions.updateViewport,
+    closeTab: actions.closeTab
   }
 )(Editor);
--- a/devtools/client/debugger/new/test/mochitest/browser.ini
+++ b/devtools/client/debugger/new/test/mochitest/browser.ini
@@ -742,16 +742,17 @@ skip-if = os == 'linux' && !asan # bug 1
 [browser_dbg-sources.js]
 [browser_dbg-sources-arrow-keys.js]
 [browser_dbg-sources-named-eval.js]
 [browser_dbg-sources-querystring.js]
 skip-if = true
 [browser_dbg-stepping.js]
 skip-if = debug || (verify && (os == 'win')) || (os == "win" && os_version == "6.1")
 [browser_dbg-tabs.js]
+[browser_dbg-tabs-keyboard.js]
 [browser_dbg-tabs-pretty-print.js]
 [browser_dbg-tabs-without-urls.js]
 [browser_dbg-toggling-tools.js]
 [browser_dbg-react-app.js]
 skip-if = os == "win"
 [browser_dbg-wasm-sourcemaps.js]
 skip-if = true
 [browser_dbg_rr_breakpoints-01.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-tabs-keyboard.js
@@ -0,0 +1,20 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests removing tabs with keyboard shortcuts
+
+add_task(async function() {
+  const dbg = await initDebugger("doc-scripts.html", "simple1", "simple2");
+
+  await selectSource(dbg, "simple1");
+  await selectSource(dbg, "simple2");
+  is(countTabs(dbg), 2);
+  
+  pressKey(dbg, "close");
+  waitForDispatch(dbg, "CLOSE_TAB");
+  is(countTabs(dbg), 1);
+
+  pressKey(dbg, "close");
+  waitForDispatch(dbg, "CLOSE_TAB");
+  is(countTabs(dbg), 0);
+});
--- a/devtools/client/debugger/new/test/mochitest/browser_dbg-tabs-without-urls.js
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-tabs-without-urls.js
@@ -1,15 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-function countTabs(dbg) {
-  return findElement(dbg, "sourceTabs").children.length;
-}
-
 // Test that URL-less sources have tabs added to the UI but 
 // do not persist upon reload
 add_task(async function() {
   const dbg = await initDebugger("doc-scripts.html", "simple1", "simple2");
 
   await selectSource(dbg, "simple1");
   await selectSource(dbg, "simple2");
 
--- a/devtools/client/debugger/new/test/mochitest/browser_dbg-tabs.js
+++ b/devtools/client/debugger/new/test/mochitest/browser_dbg-tabs.js
@@ -1,17 +1,13 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Tests adding and removing tabs
 
-function countTabs(dbg) {
-  return findElement(dbg, "sourceTabs").children.length;
-}
-
 add_task(async function() {
   const dbg = await initDebugger("doc-scripts.html", "simple1", "simple2");
 
   await selectSource(dbg, "simple1");
   await selectSource(dbg, "simple2");
   is(countTabs(dbg), 2);
 
   // Test reloading the debugger
--- a/devtools/client/debugger/new/test/mochitest/helpers.js
+++ b/devtools/client/debugger/new/test/mochitest/helpers.js
@@ -596,16 +596,20 @@ async function selectSource(dbg, url, li
   return waitForSelectedSource(dbg, url);
 }
 
 
 async function closeTab(dbg, url) {
   await dbg.actions.closeTab(findSource(dbg, url));
 }
 
+function countTabs(dbg) {
+  return findElement(dbg, "sourceTabs").children.length;
+}
+
 /**
  * Steps over.
  *
  * @memberof mochitest/actions
  * @param {Object} dbg
  * @return {Promise}
  * @static
  */
@@ -913,16 +917,17 @@ const cmdShift = isMac
 const endKey = isMac
   ? { code: "VK_RIGHT", modifiers: cmdOrCtrl }
   : { code: "VK_END" };
 const startKey = isMac
   ? { code: "VK_LEFT", modifiers: cmdOrCtrl }
   : { code: "VK_HOME" };
 
 const keyMappings = {
+  close: { code: "w", modifiers: cmdOrCtrl },
   debugger: { code: "s", modifiers: shiftOrAlt },
   inspector: { code: "c", modifiers: shiftOrAlt },
   quickOpen: { code: "p", modifiers: cmdOrCtrl },
   quickOpenFunc: { code: "o", modifiers: cmdShift },
   quickOpenLine: { code: ":", modifiers: cmdOrCtrl },
   fileSearch: { code: "f", modifiers: cmdOrCtrl },
   Enter: { code: "VK_RETURN" },
   ShiftEnter: { code: "VK_RETURN", modifiers: shiftOrAlt },
--- a/devtools/client/locales/en-US/debugger.properties
+++ b/devtools/client/locales/en-US/debugger.properties
@@ -537,16 +537,17 @@ xhrBreakpoints.label=Add XHR breakpoint
 # LOCALIZATION NOTE (pauseOnAnyXHR): The pause on any XHR checkbox description
 # when the debugger will pause on any XHR requests.
 pauseOnAnyXHR=Pause on any URL
 
 # LOCALIZATION NOTE (sourceTabs.closeTab): Editor source tab context menu item
 # for closing the selected tab below the mouse.
 sourceTabs.closeTab=Close tab
 sourceTabs.closeTab.accesskey=c
+sourceTabs.closeTab.key=CmdOrCtrl+W
 
 # LOCALIZATION NOTE (sourceTabs.closeOtherTabs): Editor source tab context menu item
 # for closing the other tabs.
 sourceTabs.closeOtherTabs=Close other tabs
 sourceTabs.closeOtherTabs.accesskey=o
 
 # LOCALIZATION NOTE (sourceTabs.closeTabsToEnd): Editor source tab context menu item
 # for closing the tabs to the end (the right for LTR languages) of the selected tab.