implement inverse key

This commit is contained in:
filifa 2025-12-11 23:49:34 -05:00
parent 972513ea75
commit 328c4b9e22
1 changed files with 3 additions and 2 deletions

View File

@ -55,7 +55,7 @@ function keyPress(c) {
const begin = currentInput.value.slice(0, selectionStart);
const end = currentInput.value.slice(selectionEnd);
currentInput.value = begin + c + end;
currentInput.setSelectionRange(selectionStart+1, selectionStart+1);
currentInput.setSelectionRange(selectionStart+c.length, selectionStart+c.length);
}
function backspace() {
@ -107,10 +107,11 @@ document.querySelector("#lparen").addEventListener("click", () => keyPress("("))
document.querySelector("#rparen").addEventListener("click", () => keyPress(")"));
document.querySelector("#pow").addEventListener("click", () => keyPress("^"));
document.querySelector("#inv").addEventListener("click", () => keyPress("^-1"));
document.querySelector("#clear").addEventListener("click", clear);
document.querySelector("#enter").addEventListener("click", evaluate);
document.querySelector("#backspace").addEventListener("click", backspace);
// TODO implement square root and inverse keys
// TODO implement square root key