Merge pull request #2416 from thelounge/xpaw/out-of-focus-touch

Allow out-of-focus typing on touch devices
This commit is contained in:
Jérémie Astori 2018-05-07 02:23:35 -04:00 committed by GitHub
commit 0cd6366b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -247,27 +247,25 @@ const ignoredKeys = {
224: true, // Meta
};
if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) {
$(document.body).on("keydown", (e) => {
// Ignore if target isn't body (e.g. focused into input)
// Ignore any key that uses alt modifier
// Ignore keys defined above
if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) {
return;
}
$(document.body).on("keydown", (e) => {
// Ignore if target isn't body (e.g. focused into input)
// Ignore any key that uses alt modifier
// Ignore keys defined above
if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) {
return;
}
// Ignore all ctrl keys except for ctrl+v to allow pasting
if ((e.ctrlKey || e.metaKey) && e.which !== 86) {
return;
}
// On enter, focus the input but do not propagate the event
// This way, a new line is not inserted
if (e.which === 13) {
input.trigger("focus");
return false;
}
// Ignore all ctrl keys except for ctrl+v to allow pasting
if ((e.ctrlKey || e.metaKey) && e.which !== 86) {
return;
}
// On enter, focus the input but do not propagate the event
// This way, a new line is not inserted
if (e.which === 13) {
input.trigger("focus");
});
}
return false;
}
input.trigger("focus");
});