Bug 1560320 - Dismiss autocomplete on Ctrl+A on OSX. r=Honza.

Ctrl + A moves the cursor to the beginning of the line,
so we need to dismiss autocomplete.
A test case is added to make sure this behaves as
expected.

Differential Revision: https://phabricator.services.mozilla.com/D35573

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2019-06-27 11:48:34 +00:00
Родитель 06b2ed9350
Коммит c1f5c82eda
2 изменённых файлов: 17 добавлений и 16 удалений

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

@ -133,6 +133,8 @@ class JSTerm extends Component {
autoSelect: true,
};
const isMacOS = Services.appinfo.OS === "Darwin";
const doc = this.webConsoleUI.document;
const toolbox = this.webConsoleUI.wrapper.toolbox;
const tooltipDoc = toolbox ? toolbox.doc : doc;
@ -287,6 +289,8 @@ class JSTerm extends Component {
"Ctrl-Left": onArrowLeft,
"Cmd-Left": onArrowLeft,
"Alt-Left": onArrowLeft,
// On OSX, Ctrl-A navigates to the beginning of the line.
"Ctrl-A": isMacOS ? onArrowLeft : undefined,
"Right": onArrowRight,
"Ctrl-Right": onArrowRight,
@ -859,30 +863,23 @@ class JSTerm extends Component {
* @param Event event
*/
_keyPress(event) {
const inputNode = this.inputNode;
const inputValue = this._getValue();
let inputUpdated = false;
if (event.ctrlKey) {
switch (event.charCode) {
case 97:
// control-a (goes to beginning of the line, need to clear completion)
if (!Services.appinfo.OS == "Darwin") {
break;
}
this.clearCompletion();
break;
case 101:
// control-e
// control-e (goes to end of the line, need to clear completion)
if (Services.appinfo.OS == "WINNT") {
break;
}
let lineEndPos = inputValue.length;
if (this.hasMultilineInput()) {
// find index of closest newline >= cursor
for (let i = inputNode.selectionEnd; i < lineEndPos; i++) {
if (inputValue.charAt(i) == "\r" ||
inputValue.charAt(i) == "\n") {
lineEndPos = i;
break;
}
}
}
inputNode.setSelectionRange(lineEndPos, lineEndPos);
event.preventDefault();
this.clearCompletion();
break;

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

@ -113,7 +113,11 @@ async function performTests() {
await setInputValueForAutocompletion(hud, "window.foo.item0");
prefix = getInputValue(hud).replace(/[\S]/g, " ");
checkInputCompletionValue(hud, prefix + "0", "completeNode has expected value");
EventUtils.synthesizeKey("KEY_Home");
if (Services.appinfo.OS == "Darwin") {
EventUtils.synthesizeKey("a", {ctrlKey: true});
} else {
EventUtils.synthesizeKey("KEY_Home");
}
checkInputCompletionValue(hud, "", "completeNode was cleared after hitting Home");
info("Check that hitting End hides the completion text when the popup is hidden");