diff --git a/main.js b/main.js index 32ed12f..d2d02df 100644 --- a/main.js +++ b/main.js @@ -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