diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js
index 27ead23124..ad1d889556 100644
--- a/interface/resources/html/raiseAndLowerKeyboard.js
+++ b/interface/resources/html/raiseAndLowerKeyboard.js
@@ -14,7 +14,6 @@
var isWindowFocused = true;
var isKeyboardRaised = false;
var isNumericKeyboard = false;
- var KEYBOARD_HEIGHT = 200;
function shouldRaiseKeyboard() {
var nodeName = document.activeElement.nodeName;
@@ -38,6 +37,19 @@
return document.activeElement.type === "number";
};
+ function scheduleBringToView(timeout) {
+
+ var timer = setTimeout(function () {
+ clearTimeout(timer);
+
+ var elementRect = document.activeElement.getBoundingClientRect();
+ var absoluteElementTop = elementRect.top + window.scrollY;
+ var middle = absoluteElementTop - (window.innerHeight / 2);
+
+ window.scrollTo(0, middle);
+ }, timeout);
+ }
+
setInterval(function () {
var keyboardRaised = shouldRaiseKeyboard();
var numericKeyboard = shouldSetNumeric();
@@ -56,13 +68,8 @@
}
if (!isKeyboardRaised) {
- var delta = document.activeElement.getBoundingClientRect().bottom + 10
- - (document.body.clientHeight - KEYBOARD_HEIGHT);
- if (delta > 0) {
- setTimeout(function () {
- document.body.scrollTop += delta;
- }, 500); // Allow time for keyboard to be raised in QML.
- }
+ scheduleBringToView(250); // Allow time for keyboard to be raised in QML.
+ // 2DO: should it be rather done from 'client area height changed' event?
}
isKeyboardRaised = keyboardRaised;
@@ -70,6 +77,13 @@
}
}, POLL_FREQUENCY);
+ window.addEventListener("click", function () {
+ var keyboardRaised = shouldRaiseKeyboard();
+ if(keyboardRaised && isKeyboardRaised) {
+ scheduleBringToView(150);
+ }
+ });
+
window.addEventListener("focus", function () {
isWindowFocused = true;
});