From ff550053da3041e270a4b1232ddc630b889a3c95 Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Thu, 28 Mar 2019 15:32:22 -0700 Subject: [PATCH] create DisplayExpressionToken only when necessary + fix the failed unit test --- src/CalcViewModel/StandardCalculatorViewModel.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index 26c05408..48ed3a9b 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -355,24 +355,25 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptrSize) { auto existingItem = m_ExpressionTokens->GetAt(i); - if (type == existingItem->Type && expressionToken->Token->Equals(currentTokenString)) + if (type == existingItem->Type && existingItem->Token->Equals(currentTokenString)) { existingItem->TokenPosition = i; existingItem->IsTokenEditable = isEditable; - existingItem->CommandIndex = expressionToken->CommandIndex; + existingItem->CommandIndex = 0; } else { + auto expressionToken = ref new DisplayExpressionToken(currentTokenString, i, isEditable, type); m_ExpressionTokens->InsertAt(i, expressionToken); } } else { + auto expressionToken = ref new DisplayExpressionToken(currentTokenString, i, isEditable, type); m_ExpressionTokens->Append(expressionToken); } }