From bb7fd3644dac1f4a2ba88ac95f5dabe188ecd0e3 Mon Sep 17 00:00:00 2001 From: JoannesJ Date: Fri, 8 Feb 2019 03:56:22 +0100 Subject: [PATCH] Patch dgg chat stealing focus issue (not a proper fix) This addresses github.com/MemeLabs/Rustla2/issues/117 Not a proper fix, as typing in chat directly after switching will steal a few characters mid sentence. Though it's better than nothing, until we can implement a proper fix. --- assets/chat/js/chat.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/assets/chat/js/chat.js b/assets/chat/js/chat.js index 4ff097be..2534809b 100644 --- a/assets/chat/js/chat.js +++ b/assets/chat/js/chat.js @@ -338,8 +338,18 @@ class Chat { // Visibility document.addEventListener('visibilitychange', debounce(100, () => { this.ishidden = (document['visibilityState'] || 'visible') !== 'visible'; - if (!this.ishidden) focusIfNothingSelected(this); - else ChatMenu.closeMenus(this); + + if (!this.ishidden) { + focusIfNothingSelected(this); + + // Shotgun some focus requests to battle an external focus steal + // github.com/MemeLabs/Rustla2/issues/117 + setTimeout(() => focusIfNothingSelected(this), 1600); + setTimeout(() => focusIfNothingSelected(this), 1800); + setTimeout(() => focusIfNothingSelected(this), 2000); + } else { + ChatMenu.closeMenus(this); + } }), true); // Resize