Skip to content

Commit

Permalink
typing infix operators inserts previous solution before it
Browse files Browse the repository at this point in the history
  • Loading branch information
antingle committed May 1, 2022
1 parent 6c101f4 commit 01cd44a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Calculator/CalculatorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ struct CalculatorView: View {
},
// On every update of the text by keyboard
onTextChange: { newExpression in
if !history.isEmpty &&
(newExpression == "+" ||
newExpression == "*" ||
newExpression == "/" ||
newExpression == "^" ||
newExpression == "%")
{
expression.insert(contentsOf: history[0].solution, at: expression.startIndex)
}
do {
historyIndex = -1 // reset the history index counter for arrow keys
solution = try evaluateExpression(newExpression)
Expand Down

0 comments on commit 01cd44a

Please sign in to comment.