From 910b5a425f5175550ed529d43bfac69f0ee575fc Mon Sep 17 00:00:00 2001 From: bakk Date: Fri, 28 May 2021 19:08:15 +0200 Subject: [PATCH] kalk_web: Avoid automatic scrolling during input on phones --- kalk_web/public/index.html | 2 ++ kalk_web/src/KalkCalculator.svelte | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kalk_web/public/index.html b/kalk_web/public/index.html index 1445316..e9c9d71 100644 --- a/kalk_web/public/index.html +++ b/kalk_web/public/index.html @@ -38,6 +38,8 @@ height: 100%; margin: 0; padding: 0; + padding-top: 300px; + padding-bottom: 300px; } #wrapper { diff --git a/kalk_web/src/KalkCalculator.svelte b/kalk_web/src/KalkCalculator.svelte index 0b3b236..2ae7253 100644 --- a/kalk_web/src/KalkCalculator.svelte +++ b/kalk_web/src/KalkCalculator.svelte @@ -164,7 +164,7 @@ } function insertText(input: string) { - inputElement.focus(); + inputElement.focus({ preventScroll: true }); let cursorPos = getCursorPos(inputElement); const textContent = inputElement.textContent; let movementOffset = input.length; @@ -196,8 +196,16 @@ const [highlighted, offset] = highlight(newString); inputElement.innerHTML = highlighted; - inputElement.focus(); + inputElement.focus({ preventScroll: true }); setCursorPos(inputElement, cursorPos - offset + movementOffset); + + // I know this sucks, but it keeps scrolling away on some browsers >:( + let i = 0; + setInterval(() => { + if (i == 60) return; + calculatorElement.scrollIntoView(); + i++; + }, 20); } function focus(element: HTMLInputElement) {