Bug 1624333 - Don't close autocomplete popup when pressing Delete key. r=Honza.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 26 Mar 2020 07:18:23 +0000
changeset 520477 1fe283e3bb59d87eb597ee4a0287fbafe264bc34
parent 520476 3beaf308af00777f66e62a4da013668777e68ca5
child 520478 46bf06a42ba623133cfdaceac9d3f9f778975b79
push id37252
push usermalexandru@mozilla.com
push dateThu, 26 Mar 2020 15:34:27 +0000
treeherdermozilla-central@31360ced8ff8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1624333
milestone76.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 1624333 - Don't close autocomplete popup when pressing Delete key. r=Honza. If the delete key is pressed, even if the input isn't modified, codeMirror will still emit _onEditorBeforeChange, which would close the popup in the end. That's not something we should do, so in this patch, we bail out if we detect that there was no changes in the input. A test is added to ensure this works as expected and we avoid regression. Differential Revision: https://phabricator.services.mozilla.com/D67903
devtools/client/webconsole/components/Input/JSTerm.js
devtools/client/webconsole/test/browser/_jsterm.ini
devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_del_key.js
--- a/devtools/client/webconsole/components/Input/JSTerm.js
+++ b/devtools/client/webconsole/components/Input/JSTerm.js
@@ -745,16 +745,28 @@ class JSTerm extends Component {
    */
   _onEditorBeforeChange(cm, change) {
     // If the user did not type a character that matches the completion text, then we
     // clear it before the change is done to prevent a visual glitch.
     // See Bugs 1491776 & 1558248.
     const { from, to, origin, text } = change;
     const isAddedText =
       from.line === to.line && from.ch === to.ch && origin === "+input";
+
+    // if there was no changes (hitting delete on an empty input, or suppr when at the end
+    // of the input), we bail out.
+    if (
+      !isAddedText &&
+      origin === "+delete" &&
+      from.line === to.line &&
+      from.ch === to.ch
+    ) {
+      return;
+    }
+
     const addedText = text.join("");
     const completionText = this.getAutoCompletionText();
 
     const addedCharacterMatchCompletion =
       isAddedText && completionText.startsWith(addedText);
 
     const addedCharacterMatchPopupItem =
       isAddedText &&
--- a/devtools/client/webconsole/test/browser/_jsterm.ini
+++ b/devtools/client/webconsole/test/browser/_jsterm.ini
@@ -29,16 +29,17 @@ support-files =
 [browser_jsterm_autocomplete_await.js]
 [browser_jsterm_autocomplete_toggle.js]
 [browser_jsterm_autocomplete_cached_results.js]
 [browser_jsterm_autocomplete_commands.js]
 [browser_jsterm_autocomplete_control_space.js]
 [browser_jsterm_autocomplete_crossdomain_iframe.js]
 [browser_jsterm_autocomplete_disabled.js]
 [browser_jsterm_autocomplete_eager_evaluation.js]
+[browser_jsterm_autocomplete_del_key.js]
 [browser_jsterm_autocomplete_escape_key.js]
 [browser_jsterm_autocomplete_expression_variables.js]
 [browser_jsterm_autocomplete_extraneous_closing_brackets.js]
 [browser_jsterm_autocomplete_getters_cache.js]
 [browser_jsterm_autocomplete_getters_cancel.js]
 [browser_jsterm_autocomplete_getters_confirm.js]
 [browser_jsterm_autocomplete_getters_learn_more_link.js]
 [browser_jsterm_autocomplete_helpers.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/browser/browser_jsterm_autocomplete_del_key.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// See Bug 585991.
+
+const TEST_URI = `data:text/html;charset=utf-8,
+<head>
+  <script>
+    foo = {
+      item0: "value0",
+      item1: "value1",
+    };
+  </script>
+</head>
+<body>Autocomplete popup delete key usage test</body>`;
+
+add_task(async function() {
+  const hud = await openNewTabAndConsole(TEST_URI);
+  const { jsterm } = hud;
+  info("web console opened");
+
+  const { autocompletePopup: popup } = jsterm;
+  await setInputValueForAutocompletion(hud, "foo.i");
+
+  ok(popup.isOpen, "popup is open");
+
+  info("press Delete");
+  const onPopupClose = popup.once("popup-closed");
+  const onTimeout = wait(1000).then(() => "timeout");
+  EventUtils.synthesizeKey("KEY_Delete");
+
+  const result = await Promise.race([onPopupClose, onTimeout]);
+
+  is(result, "timeout", "The timeout won the race");
+  ok(popup.isOpen, "popup is open after hitting delete key");
+
+  await closeAutocompletePopup(hud);
+});