FIX: Don't crash the browser when tapping autocomplete suggestions on Android/Gboard (#15076)
This is a workaround for an annoying bug that crashes the browser when an autocomplete suggestion is selected on Android if the virtual keyboard is Gboard. It's specific to Gboard because it sometimes sends `keydown` and `keyup` events twice for a single key press, more details can be found here: https://meta.discourse.org/t/emoji-selector-crashes-the-message-editor-in-android-chrome/187009/24?u=osama.
This commit is contained in:
parent
ded9fe950a
commit
8fd10e6414
|
@ -309,9 +309,22 @@ export default function (options) {
|
||||||
}
|
}
|
||||||
ul.find("li").click(function () {
|
ul.find("li").click(function () {
|
||||||
selectedOption = ul.find("li").index(this);
|
selectedOption = ul.find("li").index(this);
|
||||||
completeTerm(autocompleteOptions[selectedOption]);
|
// hack for Gboard, see meta.discourse.org/t/-/187009/24
|
||||||
if (!options.single) {
|
if (autocompleteOptions == null) {
|
||||||
me.focus();
|
const opts = { ...options, _gboard_hack_force_lookup: true };
|
||||||
|
const forcedAutocompleteOptions = dataSource(prevTerm, opts);
|
||||||
|
forcedAutocompleteOptions?.then((data) => {
|
||||||
|
updateAutoComplete(data);
|
||||||
|
completeTerm(autocompleteOptions[selectedOption]);
|
||||||
|
if (!options.single) {
|
||||||
|
me.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
completeTerm(autocompleteOptions[selectedOption]);
|
||||||
|
if (!options.single) {
|
||||||
|
me.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -398,7 +411,11 @@ export default function (options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dataSource(term, opts) {
|
function dataSource(term, opts) {
|
||||||
if (prevTerm === term) {
|
const force = opts._gboard_hack_force_lookup;
|
||||||
|
if (force) {
|
||||||
|
delete opts._gboard_hack_force_lookup;
|
||||||
|
}
|
||||||
|
if (prevTerm === term && !force) {
|
||||||
return SKIP;
|
return SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue