Bug 1668117 - [devtools] do not load KeyShortcuts from devtools-modules in debugger r=nchevobbe
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 02 Oct 2020 15:39:13 +0000
changeset 551359 048b07dd19a8fc52b8d352fd6ed28ffe3bbf2dbd
parent 551358 9ecab39fd6d4059072d3231df445d586ebb9772a
child 551360 06e10dd4a6c42274800f957048457577c3788ce1
push id127820
push userjdescottes@mozilla.com
push dateFri, 02 Oct 2020 22:08:32 +0000
treeherderautoland@ba4685a82eea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1668117
milestone83.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 1668117 - [devtools] do not load KeyShortcuts from devtools-modules in debugger r=nchevobbe Depends on D91856 The shared key-shortcuts helper calls handler with a different signature compared to the one in devtools-modules. The devtools-module one passed two arguments, the event itself being the 2nd argument. The shared one passes only the event. Updated the debugger codebase to stop expecting two arguments. The first argument was never used. Differential Revision: https://phabricator.services.mozilla.com/D91857
devtools/client/debugger/src/components/App.js
devtools/client/debugger/src/components/Editor/SearchBar.js
devtools/client/debugger/src/components/Editor/index.js
devtools/client/debugger/src/components/ProjectSearch.js
devtools/client/debugger/src/components/SecondaryPanes/CommandBar.js
devtools/client/debugger/src/components/SecondaryPanes/tests/CommandBar.spec.js
--- a/devtools/client/debugger/src/components/App.js
+++ b/devtools/client/debugger/src/components/App.js
@@ -19,17 +19,19 @@ import {
   getActiveSearch,
   getQuickOpenEnabled,
   getOrientation,
 } from "../selectors";
 
 import type { OrientationType } from "../reducers/types";
 import type { Source } from "../types";
 
-import { KeyShortcuts } from "devtools-modules";
+// $FlowIgnore
+const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
+
 import Services from "devtools-services";
 const shortcuts = new KeyShortcuts({ window });
 
 const { appinfo } = Services;
 
 const isMacOS = appinfo.OS === "Darwin";
 
 const horizontalLayoutBreakpoint = window.matchMedia("(min-width: 800px)");
@@ -108,28 +110,28 @@ class App extends Component<Props, State
     };
   }
 
   componentDidMount() {
     horizontalLayoutBreakpoint.addListener(this.onLayoutChange);
     verticalLayoutBreakpoint.addListener(this.onLayoutChange);
     this.setOrientation();
 
-    shortcuts.on(L10N.getStr("symbolSearch.search.key2"), (_, e) =>
-      this.toggleQuickOpenModal(_, e, "@")
+    shortcuts.on(L10N.getStr("symbolSearch.search.key2"), e =>
+      this.toggleQuickOpenModal(e, "@")
     );
 
     const searchKeys = [
       L10N.getStr("sources.search.key2"),
       L10N.getStr("sources.search.alt.key"),
     ];
     searchKeys.forEach(key => shortcuts.on(key, this.toggleQuickOpenModal));
 
-    shortcuts.on(L10N.getStr("gotoLineModal.key3"), (_, e) =>
-      this.toggleQuickOpenModal(_, e, ":")
+    shortcuts.on(L10N.getStr("gotoLineModal.key3"), e =>
+      this.toggleQuickOpenModal(e, ":")
     );
 
     shortcuts.on("Escape", this.onEscape);
     shortcuts.on("Cmd+/", this.onCommandSlash);
   }
 
   componentWillUnmount() {
     horizontalLayoutBreakpoint.removeListener(this.onLayoutChange);
@@ -145,17 +147,17 @@ class App extends Component<Props, State
     ];
     searchKeys.forEach(key => shortcuts.off(key, this.toggleQuickOpenModal));
 
     shortcuts.off(L10N.getStr("gotoLineModal.key3"), this.toggleQuickOpenModal);
 
     shortcuts.off("Escape", this.onEscape);
   }
 
-  onEscape = (_: mixed, e: KeyboardEvent) => {
+  onEscape = (e: KeyboardEvent) => {
     const {
       activeSearch,
       closeActiveSearch,
       closeQuickOpen,
       quickOpenEnabled,
     } = this.props;
     const { shortcutsModalEnabled } = this.state;
 
@@ -178,21 +180,17 @@ class App extends Component<Props, State
   onCommandSlash = () => {
     this.toggleShortcutsModal();
   };
 
   isHorizontal() {
     return this.props.orientation === "horizontal";
   }
 
-  toggleQuickOpenModal = (
-    _: mixed,
-    e: SyntheticEvent<HTMLElement>,
-    query?: string
-  ) => {
+  toggleQuickOpenModal = (e: SyntheticEvent<HTMLElement>, query?: string) => {
     const { quickOpenEnabled, openQuickOpen, closeQuickOpen } = this.props;
 
     e.preventDefault();
     e.stopPropagation();
 
     if (quickOpenEnabled === true) {
       closeQuickOpen();
       return;
--- a/devtools/client/debugger/src/components/Editor/SearchBar.js
+++ b/devtools/client/debugger/src/components/Editor/SearchBar.js
@@ -113,24 +113,22 @@ class SearchBar extends Component<Props,
     this.doSearch = debounce(this.doSearch, 100);
     const { shortcuts } = this.context;
     const {
       searchShortcut,
       searchAgainShortcut,
       shiftSearchAgainShortcut,
     } = getShortcuts();
 
-    shortcuts.on(searchShortcut, (_, e) => this.toggleSearch(e));
-    shortcuts.on("Escape", (_, e) => this.onEscape(e));
+    shortcuts.on(searchShortcut, this.toggleSearch);
+    shortcuts.on("Escape", this.onEscape);
 
-    shortcuts.on(shiftSearchAgainShortcut, (_, e) =>
-      this.traverseResults(e, true)
-    );
+    shortcuts.on(shiftSearchAgainShortcut, e => this.traverseResults(e, true));
 
-    shortcuts.on(searchAgainShortcut, (_, e) => this.traverseResults(e, false));
+    shortcuts.on(searchAgainShortcut, e => this.traverseResults(e, false));
   }
 
   componentDidUpdate(prevProps: Props, prevState: State) {
     if (this.refs.resultList && this.refs.resultList.refs) {
       scrollList(this.refs.resultList.refs, this.state.selectedResultIndex);
     }
   }
 
--- a/devtools/client/debugger/src/components/Editor/index.js
+++ b/devtools/client/debugger/src/components/Editor/index.js
@@ -258,17 +258,17 @@ class Editor extends PureComponent<Props
     );
     shortcuts.on(
       L10N.getStr("sourceTabs.closeTab.key"),
       this.onCloseShortcutPress
     );
     shortcuts.on("Esc", this.onEscape);
   }
 
-  onCloseShortcutPress = (key: mixed, e: KeyboardEvent) => {
+  onCloseShortcutPress = (e: KeyboardEvent) => {
     const { cx, selectedSource } = this.props;
     if (selectedSource) {
       e.preventDefault();
       e.stopPropagation();
       this.props.closeTab(cx, selectedSource, "shortcut");
     }
   };
 
@@ -293,29 +293,29 @@ class Editor extends PureComponent<Props
     if (!selectedSource) {
       return;
     }
 
     const line = getCursorLine(codeMirror);
     return toSourceLine(selectedSource.id, line);
   }
 
-  onToggleBreakpoint = (key: mixed, e: KeyboardEvent) => {
+  onToggleBreakpoint = (e: KeyboardEvent) => {
     e.preventDefault();
     e.stopPropagation();
 
     const line = this.getCurrentLine();
     if (typeof line !== "number") {
       return;
     }
 
     this.props.toggleBreakpointAtLine(this.props.cx, line);
   };
 
-  onToggleConditionalPanel = (key: mixed, e: KeyboardEvent) => {
+  onToggleConditionalPanel = (e: KeyboardEvent) => {
     e.stopPropagation();
     e.preventDefault();
 
     const {
       conditionalPanelLocation,
       closeConditionalPanel,
       openConditionalPanel,
       selectedSource,
@@ -385,17 +385,17 @@ class Editor extends PureComponent<Props
   }
 
   /*
    * The default Esc command is overridden in the CodeMirror keymap to allow
    * the Esc keypress event to be catched by the toolbox and trigger the
    * split console. Restore it here, but preventDefault if and only if there
    * is a multiselection.
    */
-  onEscape = (key: mixed, e: KeyboardEvent) => {
+  onEscape = (e: KeyboardEvent) => {
     if (!this.state.editor) {
       return;
     }
 
     const { codeMirror } = this.state.editor;
     if (codeMirror.listSelections().length > 1) {
       codeMirror.execCommand("singleSelection");
       e.preventDefault();
--- a/devtools/client/debugger/src/components/ProjectSearch.js
+++ b/devtools/client/debugger/src/components/ProjectSearch.js
@@ -124,17 +124,17 @@ export class ProjectSearch extends Compo
       this.setState({ inputValue: this.props.query });
     }
   }
 
   doSearch(searchTerm: string) {
     this.props.searchSources(this.props.cx, searchTerm);
   }
 
-  toggleProjectTextSearch = (key: string, e: KeyboardEvent) => {
+  toggleProjectTextSearch = (e: KeyboardEvent) => {
     const { cx, closeProjectSearch, setActiveSearch } = this.props;
     if (e) {
       e.preventDefault();
     }
 
     if (this.isProjectSearchEnabled()) {
       return closeProjectSearch(cx);
     }
--- a/devtools/client/debugger/src/components/SecondaryPanes/CommandBar.js
+++ b/devtools/client/debugger/src/components/SecondaryPanes/CommandBar.js
@@ -115,24 +115,24 @@ class CommandBar extends Component<Props
       COMMANDS.forEach(action => shortcuts.off(getKeyForOS("WINNT", action)));
     }
   }
 
   componentDidMount() {
     const { shortcuts } = this.context;
 
     COMMANDS.forEach(action =>
-      shortcuts.on(getKey(action), (_, e) => this.handleEvent(e, action))
+      shortcuts.on(getKey(action), e => this.handleEvent(e, action))
     );
 
     if (isMacOS) {
       // The Mac supports both the Windows Function keys
       // as well as the Mac non-Function keys
       COMMANDS.forEach(action =>
-        shortcuts.on(getKeyForOS("WINNT", action), (_, e) =>
+        shortcuts.on(getKeyForOS("WINNT", action), e =>
           this.handleEvent(e, action)
         )
       );
     }
   }
 
   handleEvent(e: Event, action: CommandActionType) {
     const { cx } = this.props;
--- a/devtools/client/debugger/src/components/SecondaryPanes/tests/CommandBar.spec.js
+++ b/devtools/client/debugger/src/components/SecondaryPanes/tests/CommandBar.spec.js
@@ -33,17 +33,17 @@ describe("CommandBar", () => {
     // this will be an array where each item is itself a two item array
     // containing the key code and the corresponding handler for that key code
     const keyEventHandlers = context.shortcuts.on.mock.calls;
 
     // simulate pressing the F8 key by calling the F8 handlers
     keyEventHandlers
       .filter(i => i[0] === "F8")
       .forEach(([_, handler]) => {
-        handler(null, mockEvent);
+        handler(mockEvent);
       });
 
     expect(props.breakOnNext).toHaveBeenCalled();
     expect(props.resume).not.toHaveBeenCalled();
   });
 
   it("f8 key command calls props.resume when in paused state", () => {
     const props = {
@@ -68,14 +68,14 @@ describe("CommandBar", () => {
     // this will be an array where each item is itself a two item array
     // containing the key code and the corresponding handler for that key code
     const keyEventHandlers = context.shortcuts.on.mock.calls;
 
     // simulate pressing the F8 key by calling the F8 handlers
     keyEventHandlers
       .filter(i => i[0] === "F8")
       .forEach(([_, handler]) => {
-        handler(null, mockEvent);
+        handler(mockEvent);
       });
     expect(props.resume).toHaveBeenCalled();
     expect(props.breakOnNext).not.toHaveBeenCalled();
   });
 });