Merge pull request #2536 from thelounge/xpaw/fix-2473

Focus into input if trying to type into any non-input element
This commit is contained in:
Jérémie Astori 2018-06-10 13:35:10 -04:00 committed by GitHub
commit e3808068af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -247,11 +247,10 @@ const ignoredKeys = {
224: true, // Meta
};
$(document.body).on("keydown", (e) => {
// Ignore if target isn't body (e.g. focused into input)
$(document).on("keydown", (e) => {
// Ignore any key that uses alt modifier
// Ignore keys defined above
if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) {
if (e.altKey || ignoredKeys[e.which]) {
return;
}
@ -260,6 +259,13 @@ $(document.body).on("keydown", (e) => {
return;
}
const tagName = e.target.tagName;
// Ignore if we're already typing into <input> or <textarea>
if (tagName === "INPUT" || tagName === "TEXTAREA") {
return;
}
// On enter, focus the input but do not propagate the event
// This way, a new line is not inserted
if (e.which === 13) {