Remove formatting when evaluating

This commit is contained in:
Sad Ellie 2023-02-25 17:03:30 +04:00
parent 827a42bf49
commit 942ea853f0

View File

@ -98,9 +98,8 @@ internal class CalculatorViewModel @Inject constructor(
// Called when user clicks "=" on a keyboard // Called when user clicks "=" on a keyboard
fun evaluate() { fun evaluate() {
// Input and output can change while saving in history. This way we cache it here (i think) // Input and output can change while saving in history. This way we cache it here (i think)
val currentInput = textFieldController.input.value.text
val output = _output.value val output = _output.value
if (!Expression(currentInput.clean).checkSyntax()) return if (!Expression(textFieldController.inputTextWithoutFormatting()).checkSyntax()) return
// Save to history // Save to history
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
@ -120,7 +119,7 @@ internal class CalculatorViewModel @Inject constructor(
fun onCursorChange(selection: IntRange) = textFieldController.moveCursor(selection) fun onCursorChange(selection: IntRange) = textFieldController.moveCursor(selection)
private fun calculateInput() { private fun calculateInput() {
val currentInput = textFieldController.input.value.text val currentInput = textFieldController.inputTextWithoutFormatting()
// Input is empty, don't calculate // Input is empty, don't calculate
if (currentInput.isEmpty()) { if (currentInput.isEmpty()) {
_output.update { "" } _output.update { "" }