web: Fixed double closed parenthesis on phone

This commit is contained in:
bakk 2021-06-05 12:28:17 +02:00
parent 8136bf2b6e
commit b6812cb894
2 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@paddim8/kalk-component", "name": "@paddim8/kalk-component",
"version": "1.3.0", "version": "1.3.1",
"description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.", "description": "A Svelte component for kalk, a calculator that supports user-defined functions and variables.",
"svelte": "src/main.ts", "svelte": "src/main.ts",
"main": "public/build/bundle.js", "main": "public/build/bundle.js",

View File

@ -46,6 +46,7 @@
let inputElement: HTMLTextAreaElement; let inputElement: HTMLTextAreaElement;
let highlightedTextElement: HTMLElement; let highlightedTextElement: HTMLElement;
let hasBeenInteractedWith = false; let hasBeenInteractedWith = false;
let ignoreNextInput = false;
function setText(text: string) { function setText(text: string) {
const [highlighted, offset] = highlight(text); const [highlighted, offset] = highlight(text);
@ -188,6 +189,11 @@
} }
function handleInput(e: Event) { function handleInput(e: Event) {
if (ignoreNextInput) {
ignoreNextInput = false;
return;
}
const event = e as InputEvent; const event = e as InputEvent;
const target = event.target as HTMLInputElement; const target = event.target as HTMLInputElement;
setText(target.value == "\n" ? "" : target.value); setText(target.value == "\n" ? "" : target.value);
@ -249,6 +255,7 @@
input = ", "; input = ", ";
} }
ignoreNextInput = true;
inputElement.setRangeText( inputElement.setRangeText(
input, input,
inputElement.selectionStart, inputElement.selectionStart,
@ -256,6 +263,7 @@
"end" "end"
); );
setText(inputElement.value); setText(inputElement.value);
ignoreNextInput = false;
offsetCaret(offset); offsetCaret(offset);
inputElement.focus({ preventScroll: true }); inputElement.focus({ preventScroll: true });
} }