From 84e8e21d8512b80a80d8765601200936de7da058 Mon Sep 17 00:00:00 2001
From: Thijs Wenker <me@thoys.nl>
Date: Mon, 19 Nov 2018 21:08:21 +0100
Subject: [PATCH] don't trigger virtual keyboard scroll on non input focus.

---
 interface/resources/html/raiseAndLowerKeyboard.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js
index 8cdb3c2327..db8ff24fcb 100644
--- a/interface/resources/html/raiseAndLowerKeyboard.js
+++ b/interface/resources/html/raiseAndLowerKeyboard.js
@@ -18,7 +18,7 @@
     window.isKeyboardRaised = false;
     window.isNumericKeyboard = false;
     window.isPasswordField = false;
-    window.lastActiveElement = null;
+    window.lastActiveInputElement = null;
 
     function getActiveElement() {
         return document.activeElement;
@@ -70,11 +70,15 @@
         var keyboardRaised = shouldRaiseKeyboard();
         var numericKeyboard = shouldSetNumeric();
         var passwordField = shouldSetPasswordField();
-        var activeElement = getActiveElement();
+        var activeInputElement = null;
+        // Only set the active input element when there is an input element focussed, otherwise it will scroll on body focus as well.
+        if (keyboardRaised) {
+            activeInputElement = getActiveElement();
+        }
 
         if (isWindowFocused &&
             (keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard
-                || passwordField !== window.isPasswordField || activeElement !== window.lastActiveElement)) {
+                || passwordField !== window.isPasswordField || activeInputElement !== window.lastActiveInputElement)) {
 
             if (typeof EventBridge !== "undefined" && EventBridge !== null) {
                 EventBridge.emitWebEvent(
@@ -96,7 +100,7 @@
             window.isKeyboardRaised = keyboardRaised;
             window.isNumericKeyboard = numericKeyboard;
             window.isPasswordField = passwordField;
-            window.lastActiveElement = activeElement;
+            window.lastActiveInputElement = activeInputElement;
         }
     }, POLL_FREQUENCY);