kalk_web: Avoid automatic scrolling during input on phones

This commit is contained in:
bakk 2021-05-28 19:08:15 +02:00
parent 27d96ca3c0
commit 4b0bb9cc13
2 changed files with 12 additions and 2 deletions

View File

@ -38,6 +38,8 @@
height: 100%;
margin: 0;
padding: 0;
padding-top: 300px;
padding-bottom: 300px;
}
#wrapper {

View File

@ -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) {