Bug 1557324 - Fix JSTerm keyboard navigation in old input. r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Tue, 11 Jun 2019 08:26:22 +0000
changeset 478206 be1ba46ab9fd608f8fb61882d0e23ffe01f8739e
parent 478205 de1dc8a5ce5403163d5b2d4215795ca429358433
child 478207 eaa4313efee40f023031a8e51e3564479be68933
push id87584
push usernchevobbe@mozilla.com
push dateTue, 11 Jun 2019 08:29:40 +0000
treeherderautoland@be1ba46ab9fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1557324
milestone69.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 1557324 - Fix JSTerm keyboard navigation in old input. r=Honza. Hitting Ctrl+ArrowRight didn't have any effect on windows/linux. The patch fixes this and add a test to make sure a user can navigate from word to word using Ctrl (or Alt on OSX) and Arrow Left/Right keys. Differential Revision: https://phabricator.services.mozilla.com/D34312
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
@@ -942,17 +942,16 @@ class JSTerm extends Component {
 
       // 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();
           event.preventDefault();
         }
         this.clearCompletion();
-        event.preventDefault();
       }
 
       // control-enter should execute the current input if codeMirror
       // is not enabled but editor mode is enabled.
       if (event.keyCode === KeyCodes.DOM_VK_RETURN) {
         if (this.hasAutocompletionSuggestion()) {
           this.acceptProposedCompletion();
         } else if (this.props.editorMode) {
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_autocomplete_arrow_keys.js
@@ -14,27 +14,28 @@ const TEST_URI = `data:text/html;charset
       bbb: "b",
       bbbb: "b",
     }));
   </script></head><body>Autocomplete text navigation key usage test</body>`;
 
 add_task(async function() {
   // Run test with legacy JsTerm
   await pushPref("devtools.webconsole.jsterm.codeMirror", false);
-  await performTests();
+  await performTests(true);
   // And then run it with the CodeMirror-powered one.
   await pushPref("devtools.webconsole.jsterm.codeMirror", true);
   await performTests();
 });
 
-async function performTests() {
+async function performTests(oldJsterm) {
   const hud = await openNewTabAndConsole(TEST_URI);
   const { jsterm } = hud;
   const { autocompletePopup: popup } = jsterm;
 
+  await checkWordNavigation(hud, oldJsterm);
   await checkArrowLeftDismissPopup(hud);
   await checkArrowLeftDismissCompletion(hud);
   await checkArrowRightAcceptCompletion(hud);
 
   info("Test that Ctrl/Cmd + Right closes the popup if there's text after cursor");
   setInputValue(hud, ".");
   EventUtils.synthesizeKey("KEY_ArrowLeft");
   const onPopUpOpen = popup.once("popup-opened");
@@ -174,8 +175,56 @@ async function checkArrowRightAcceptComp
     await onPopUpClose;
 
     checkInputValueAndCursorPosition(hud, "window.foo.bbb|");
     is(popup.isOpen, false, "popup is closed");
     checkInputCompletionValue(hud, "", "completeNode is empty");
   }
   setInputValue(hud, "");
 }
+
+async function checkWordNavigation(hud, oldJsterm) {
+  const accelKey = Services.appinfo.OS == "Darwin"
+    ? "altKey"
+    : "ctrlKey";
+  const goLeft = () => EventUtils.synthesizeKey("KEY_ArrowLeft", {[accelKey]: true});
+  const goRight = () => EventUtils.synthesizeKey("KEY_ArrowRight", {[accelKey]: true});
+  const isWindowsAndOldJsTerm = Services.appinfo.OS == "WINNT" && oldJsterm;
+
+  setInputValue(hud, "aa bb cc dd");
+  checkInputValueAndCursorPosition(hud, "aa bb cc dd|");
+
+  goRight();
+  checkInputValueAndCursorPosition(hud, "aa bb cc dd|");
+
+  goLeft();
+  checkInputValueAndCursorPosition(hud, "aa bb cc |dd");
+
+  goLeft();
+  checkInputValueAndCursorPosition(hud, "aa bb |cc dd");
+
+  goLeft();
+  checkInputValueAndCursorPosition(hud, "aa |bb cc dd");
+
+  goLeft();
+  checkInputValueAndCursorPosition(hud, "|aa bb cc dd");
+
+  goLeft();
+  checkInputValueAndCursorPosition(hud, "|aa bb cc dd");
+
+  goRight();
+  // Windows differ from other platforms, going to the start of the next string.
+  let expectedInput = isWindowsAndOldJsTerm ? "aa |bb cc dd" : "aa| bb cc dd";
+  checkInputValueAndCursorPosition(hud, expectedInput);
+
+  goRight();
+  expectedInput = isWindowsAndOldJsTerm ? "aa bb |cc dd" : "aa bb| cc dd";
+  checkInputValueAndCursorPosition(hud, expectedInput);
+
+  goRight();
+  expectedInput = isWindowsAndOldJsTerm ? "aa bb cc |dd" : "aa bb cc| dd";
+  checkInputValueAndCursorPosition(hud, expectedInput);
+
+  goRight();
+  checkInputValueAndCursorPosition(hud, "aa bb cc dd|");
+
+  setInputValue(hud, "");
+}