Focus into input if trying to type into any non-input element
Fixes #2473
This commit is contained in:
parent
011bf80038
commit
3b2173c694
@ -247,11 +247,10 @@ const ignoredKeys = {
|
|||||||
224: true, // Meta
|
224: true, // Meta
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document.body).on("keydown", (e) => {
|
$(document).on("keydown", (e) => {
|
||||||
// Ignore if target isn't body (e.g. focused into input)
|
|
||||||
// Ignore any key that uses alt modifier
|
// Ignore any key that uses alt modifier
|
||||||
// Ignore keys defined above
|
// Ignore keys defined above
|
||||||
if (e.target !== document.body || e.altKey || ignoredKeys[e.which]) {
|
if (e.altKey || ignoredKeys[e.which]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,6 +259,13 @@ $(document.body).on("keydown", (e) => {
|
|||||||
return;
|
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
|
// On enter, focus the input but do not propagate the event
|
||||||
// This way, a new line is not inserted
|
// This way, a new line is not inserted
|
||||||
if (e.which === 13) {
|
if (e.which === 13) {
|
||||||
|
Loading…
Reference in New Issue
Block a user