mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
re-center focused eleemnt even if keyboard was already visible
This commit is contained in:
parent
00c3dcee2f
commit
1021aa1a0e
1 changed files with 21 additions and 9 deletions
|
@ -37,6 +37,19 @@
|
||||||
return document.activeElement.type === "number";
|
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 () {
|
setInterval(function () {
|
||||||
var keyboardRaised = shouldRaiseKeyboard();
|
var keyboardRaised = shouldRaiseKeyboard();
|
||||||
var numericKeyboard = shouldSetNumeric();
|
var numericKeyboard = shouldSetNumeric();
|
||||||
|
@ -55,15 +68,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isKeyboardRaised) {
|
if (!isKeyboardRaised) {
|
||||||
var timeout = setTimeout(function () {
|
scheduleBringToView(500); // Allow time for keyboard to be raised in QML.
|
||||||
clearTimeout(timeout);
|
|
||||||
|
|
||||||
var elementRect = document.activeElement.getBoundingClientRect();
|
|
||||||
var absoluteElementTop = elementRect.top + window.scrollY;
|
|
||||||
var middle = absoluteElementTop - (window.innerHeight / 2);
|
|
||||||
|
|
||||||
window.scrollTo(0, middle);
|
|
||||||
}, 500); // Allow time for keyboard to be raised in QML.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isKeyboardRaised = keyboardRaised;
|
isKeyboardRaised = keyboardRaised;
|
||||||
|
@ -71,6 +76,13 @@
|
||||||
}
|
}
|
||||||
}, POLL_FREQUENCY);
|
}, POLL_FREQUENCY);
|
||||||
|
|
||||||
|
window.addEventListener("click", function () {
|
||||||
|
var keyboardRaised = shouldRaiseKeyboard();
|
||||||
|
if(keyboardRaised && isKeyboardRaised) {
|
||||||
|
scheduleBringToView(150);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener("focus", function () {
|
window.addEventListener("focus", function () {
|
||||||
isWindowFocused = true;
|
isWindowFocused = true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue