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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2020-03-26 07:18:23 +00:00
Родитель c77c585d14
Коммит a67aefcc66
3 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -750,6 +750,18 @@ class JSTerm extends Component {
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();

Просмотреть файл

@ -34,6 +34,7 @@ support-files =
[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]

Просмотреть файл

@ -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);
});