web: Fixed caret position offset on button press input

This commit is contained in:
bakk 2021-06-05 00:29:05 +02:00
parent df1eef8e7f
commit adc5e14fec

View File

@ -217,10 +217,12 @@
let offset = 0; let offset = 0;
if (input == "(") { if (input == "(") {
input += ")"; input += ")";
offset = -1;
} else if (input == "=") { } else if (input == "=") {
input = " = "; input = " = ";
} else if (input == "∑") { } else if (input == "∑") {
input += "()"; input += "()";
offset = -1;
} else if (input == "∫") { } else if (input == "∫") {
input += "()"; input += "()";
offset = -1; offset = -1;
@ -240,8 +242,9 @@
inputElement.selectionEnd, inputElement.selectionEnd,
"end" "end"
); );
inputElement.selectionEnd += offset;
setText(inputElement.value); setText(inputElement.value);
inputElement.selectionStart += offset;
inputElement.selectionEnd = inputElement.selectionStart;
inputElement.focus({ preventScroll: true }); inputElement.focus({ preventScroll: true });
} }