From 03da2f09461b54a2b7fc8b119d8454212f62c8f5 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 4 May 2018 20:32:53 +1200 Subject: [PATCH] Only scroll keyboard if necessary --- interface/resources/html/raiseAndLowerKeyboard.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/interface/resources/html/raiseAndLowerKeyboard.js b/interface/resources/html/raiseAndLowerKeyboard.js index a0aa1eb7fe..b2688e3db8 100644 --- a/interface/resources/html/raiseAndLowerKeyboard.js +++ b/interface/resources/html/raiseAndLowerKeyboard.js @@ -44,15 +44,14 @@ }; function scheduleBringToView(timeout) { - - var timer = setTimeout(function () { - clearTimeout(timer); - + setTimeout(function () { + // If the element is not visible because the keyboard has been raised over the top of it, scroll it into view. var elementRect = document.activeElement.getBoundingClientRect(); - var absoluteElementTop = elementRect.top + window.scrollY; - var middle = absoluteElementTop - (window.innerHeight / 2); - - window.scrollTo(0, middle); + var VISUAL_MARGIN = 3 + var delta = elementRect.y + elementRect.height + VISUAL_MARGIN - window.innerHeight; + if (delta > 0) { + window.scrollBy(0, delta); + } }, timeout); }