mirror of
https://github.com/thelounge/thelounge
synced 2024-11-30 07:50:34 +00:00
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:
commit
e3808068af
1 changed files with 9 additions and 3 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue