Bug 1515501 - Close autocomplete popup on Cmd/Ctrl + ArrowRight; r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 10 Jan 2019 15:35:43 +0000
changeset 510390 d3aef0e30186f54f428fb6f0299a64ecd11039dd
parent 510389 392036709e44d5edf28a4dee2baf4f9c457e2e0a
child 510391 8e078c86db82c28b65d7adbfec81627f6133a6a5
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1515501
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 1515501 - Close autocomplete popup on Cmd/Ctrl + ArrowRight; r=Honza. This was causing some issue with the resulting text being non-sense. A test case is added to ensure it works as expected. Differential Revision: https://phabricator.services.mozilla.com/D15936
devtools/client/webconsole/components/JSTerm.js
devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
--- a/devtools/client/webconsole/components/JSTerm.js
+++ b/devtools/client/webconsole/components/JSTerm.js
@@ -172,16 +172,28 @@ class JSTerm extends Component {
 
         const onArrowLeft = () => {
           if (this.autocompletePopup.isOpen || this.getAutoCompletionText()) {
             this.clearCompletion();
           }
           return "CodeMirror.Pass";
         };
 
+        const onArrowRight = () => {
+          // We only want to complete on Right arrow if the completion text is
+          // displayed.
+          if (this.getAutoCompletionText()) {
+            this.acceptProposedCompletion();
+            return null;
+          }
+
+          this.clearCompletion();
+          return "CodeMirror.Pass";
+        };
+
         this.editor = new Editor({
           autofocus: true,
           enableCodeFolding: false,
           autoCloseBrackets: false,
           gutters: [],
           lineWrapping: true,
           mode: Editor.modes.js,
           styleActiveLine: false,
@@ -234,27 +246,19 @@ class JSTerm extends Component {
 
             "Down": onArrowDown,
             "Cmd-Down": onArrowDown,
 
             "Left": onArrowLeft,
             "Ctrl-Left": onArrowLeft,
             "Cmd-Left": onArrowLeft,
 
-            "Right": () => {
-              // We only want to complete on Right arrow if the completion text is
-              // displayed.
-              if (this.getAutoCompletionText()) {
-                this.acceptProposedCompletion();
-                return null;
-              }
-
-              this.clearCompletion();
-              return "CodeMirror.Pass";
-            },
+            "Right": onArrowRight,
+            "Ctrl-Right": onArrowRight,
+            "Cmd-Right": onArrowRight,
 
             "Ctrl-N": () => {
               // Control-N differs from down arrow: it ignores autocomplete state.
               // Note that we preserve the default 'down' navigation within
               // multiline text.
               if (
                 Services.appinfo.OS === "Darwin"
                 && this.canCaretGoNext()
@@ -840,16 +844,25 @@ class JSTerm extends Component {
       }
 
       if (event.keyCode === KeyCodes.DOM_VK_LEFT &&
         (this.autocompletePopup.isOpen || this.getAutoCompletionText())
       ) {
         this.clearCompletion();
       }
 
+      // We only want to complete on Right arrow if the completion text is displayed.
+      if (event.keyCode === KeyCodes.DOM_VK_RIGHT) {
+        if (this.getAutoCompletionText()) {
+          this.acceptProposedCompletion();
+        }
+        this.clearCompletion();
+        event.preventDefault();
+      }
+
       return;
     } else if (event.keyCode == KeyCodes.DOM_VK_RETURN) {
       if (!this.autocompletePopup.isOpen && (
         event.shiftKey || !Debugger.isCompilableUnit(this.getInputValue())
       )) {
         // shift return or incomplete statement
         return;
       }
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
@@ -63,19 +63,35 @@ async function performTests() {
   info("Test that arrow right selects selected autocomplete item");
   onPopUpClose = popup.once("popup-closed");
   EventUtils.synthesizeKey("KEY_ArrowRight");
   await onPopUpClose;
   checkInput("window.foo.aa|");
   is(popup.isOpen, false, "popup is closed");
   checkJsTermCompletionValue(jsterm, "", "completeNode is empty");
 
+  info("Test that Ctrl/Cmd + Left removes complete node");
   await setInputValueForAutocompletion(jsterm, "window.foo.a");
   const prefix = jsterm.getInputValue().replace(/[\S]/g, " ");
   checkJsTermCompletionValue(jsterm, prefix + "a", "completeNode has expected value");
 
   const isOSX = Services.appinfo.OS == "Darwin";
   EventUtils.synthesizeKey("KEY_ArrowLeft", {
     [isOSX ? "metaKey" : "ctrlKey"]: true,
   });
   checkJsTermCompletionValue(jsterm, "",
     "completeNode was cleared after Ctrl/Cmd + left");
+
+  info("Test that Ctrl/Cmd + Right closes the popup if there's text after cursor");
+  jsterm.setInputValue(".");
+  EventUtils.synthesizeKey("KEY_ArrowLeft");
+  onPopUpOpen = popup.once("popup-opened");
+  EventUtils.sendString("win");
+  await onPopUpOpen;
+  ok(popup.isOpen, "popup is open");
+
+  onPopUpClose = popup.once("popup-closed");
+  EventUtils.synthesizeKey("KEY_ArrowRight", {
+    [isOSX ? "metaKey" : "ctrlKey"]: true,
+  });
+  await onPopUpClose;
+  is(jsterm.getInputValue(), "win.", "input value wasn't modified");
 }