zxcodes/Calculator

Wrong calculation when press the enter button

Achmet97 opened this issue · 4 comments

Hi guys i found a bug in the code. When you input numbers by mouse an click enter from the keyboard it displays wrong calculation.
It displays the calculatoin and paste the last number you cliked with the mouse.

As you can see on video when you click the numbers by mouse and pres Enter from keyboard is displays wrong result.

bug.mp4

The happens because of some strange behavior, liveScreen() is called with 1 as argument after we press the Enter key. The calculation works fine though.

Got it, it is because when you enter inputs using mouse, the last element is still in focus, when you press "enter" using the keyboard, the code for 'enter' runs and after that liveScreen() is called for the last element that was in focus.
1+1 will give 21
1+8 will give 98
This is a default behavior of the browser with space and enter key, we can use
e.preventDefault()
inside the keyboardInputHandler() to fix this bug.

It's been fixed by @rajeevcodes0. I've merged it in the master branch.