diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp index 85f31b4..c7e4b6a 100644 --- a/src/CalcManager/CEngine/History.cpp +++ b/src/CalcManager/CEngine/History.cpp @@ -325,12 +325,6 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a // history of equations void CHistoryCollector::CompleteHistoryLine(wstring_view numStr) { - if (nullptr != m_pCalcDisplay) - { - m_pCalcDisplay->SetExpressionDisplay( - std::make_shared>>(), std::make_shared>>()); - } - if (nullptr != m_pHistoryDisplay) { unsigned int addedItemIndex = m_pHistoryDisplay->AddToHistory(m_spTokens, m_spCommands, numStr); @@ -343,6 +337,16 @@ void CHistoryCollector::CompleteHistoryLine(wstring_view numStr) ReinitHistory(); } +void CHistoryCollector::CompleteEquation(std::wstring_view numStr) +{ + // Add only '=' token and not add EQU command, because + // EQU command breaks loading from history (it duplicate history entries). + IchAddSzToEquationSz(CCalcEngine::OpCodeToString(IDC_EQU), -1); + + SetExpressionDisplay(); + CompleteHistoryLine(numStr); +} + void CHistoryCollector::ClearHistoryLine(wstring_view errStr) { if (errStr.empty()) // in case of error let the display stay as it is diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 29a79bb..73468ec 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -82,6 +82,15 @@ void CCalcEngine::ClearTemporaryValues() m_bError = false; } +void CCalcEngine::ClearDisplay() +{ + if (nullptr != m_pCalcDisplay) + { + m_pCalcDisplay->SetExpressionDisplay( + make_shared>>(), make_shared>>()); + } +} + void CCalcEngine::ProcessCommand(OpCode wParam) { if (wParam == IDC_SET_RESULT) @@ -109,6 +118,12 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) m_nTempCom = (int)wParam; } + // Clear expression shown after = sign, when user do any action. + if (!m_bNoPrevEqu) + { + ClearDisplay(); + } + if (m_bError) { if (wParam == IDC_CLEAR) @@ -403,8 +418,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) if (nullptr != m_pCalcDisplay) { m_pCalcDisplay->SetParenthesisNumber(0); - m_pCalcDisplay->SetExpressionDisplay( - make_shared>>(), make_shared>>()); + ClearDisplay(); } m_HistoryCollector.ClearHistoryLine(wstring()); @@ -494,12 +508,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) if (!m_bError) { wstring groupedString = GroupDigitsPerRadix(m_numberString, m_radix); - m_HistoryCollector.CompleteHistoryLine(groupedString); - if (nullptr != m_pCalcDisplay) - { - m_pCalcDisplay->SetExpressionDisplay( - make_shared>>(), make_shared>>()); - } + m_HistoryCollector.CompleteEquation(groupedString); } m_bChangeOp = false; diff --git a/src/CalcManager/CalculatorVector.h b/src/CalcManager/CalculatorVector.h index 4a139c8..daa80d4 100644 --- a/src/CalcManager/CalculatorVector.h +++ b/src/CalcManager/CalculatorVector.h @@ -133,24 +133,11 @@ public: } } } - - std::wstring expressionSuffix{}; - hr = GetExpressionSuffix(&expressionSuffix); - if (SUCCEEDED(hr)) - { - expression->append(expressionSuffix); - } } return hr; } - ResultCode GetExpressionSuffix(_Out_ std::wstring* suffix) - { - *suffix = L" ="; - return S_OK; - } - private: std::vector m_vector; }; diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h index 1a739af..d9772ec 100644 --- a/src/CalcManager/Header Files/CalcEngine.h +++ b/src/CalcManager/Header Files/CalcEngine.h @@ -176,6 +176,7 @@ private: void DisplayAnnounceBinaryOperator(); void SetPrimaryDisplay(const std::wstring& szText, bool isError = false); void ClearTemporaryValues(); + void ClearDisplay(); CalcEngine::Rational TruncateNumForIntMath(CalcEngine::Rational const& rat); CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op); CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs); diff --git a/src/CalcManager/Header Files/History.h b/src/CalcManager/Header Files/History.h index 3365d98..cadd234 100644 --- a/src/CalcManager/Header Files/History.h +++ b/src/CalcManager/Header Files/History.h @@ -31,6 +31,7 @@ public: void EnclosePrecInversionBrackets(); bool FOpndAddedToHistory(); void CompleteHistoryLine(std::wstring_view numStr); + void CompleteEquation(std::wstring_view numStr); void ClearHistoryLine(std::wstring_view errStr); int AddCommand(_In_ const std::shared_ptr& spCommand); void UpdateHistoryExpression(uint32_t radix, int32_t precision); diff --git a/src/CalcViewModel/HistoryItemViewModel.cpp b/src/CalcViewModel/HistoryItemViewModel.cpp index 63d5e96..9463a6b 100644 --- a/src/CalcViewModel/HistoryItemViewModel.cpp +++ b/src/CalcViewModel/HistoryItemViewModel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" @@ -52,16 +52,6 @@ String } } - if (SUCCEEDED(hr)) - { - wstring expressionSuffix{}; - hr = spTokens->GetExpressionSuffix(&expressionSuffix); - if (SUCCEEDED(hr)) - { - accExpression << expressionSuffix; - } - } - if (FAILED(hr)) { return LocalizationService::GetNarratorReadableString(fallbackExpression); diff --git a/src/CalculatorUITests/StandardModeFunctionalTests.cs b/src/CalculatorUITests/StandardModeFunctionalTests.cs index 6677c84..2418dff 100644 --- a/src/CalculatorUITests/StandardModeFunctionalTests.cs +++ b/src/CalculatorUITests/StandardModeFunctionalTests.cs @@ -102,9 +102,9 @@ public void SmokeTest_History() page.StandardOperators.EqualButton.Click(); var historyItems = page.HistoryPanel.GetAllHistoryListViewItems(); - Assert.IsTrue(historyItems[0].Text.Equals("1 × 3 = 3", StringComparison.InvariantCultureIgnoreCase)); - Assert.IsTrue(historyItems[1].Text.Equals("2 Minus ( 3 = Minus (1", StringComparison.InvariantCultureIgnoreCase)); - Assert.IsTrue(historyItems[2].Text.Equals("-3 + -2.6 = Minus (5.6", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(historyItems[0].Text.Equals("1 × 3= 3", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(historyItems[1].Text.Equals("2 Minus ( 3= Minus (1", StringComparison.InvariantCultureIgnoreCase)); + Assert.IsTrue(historyItems[2].Text.Equals("-3 + -2.6= Minus (5.6", StringComparison.InvariantCultureIgnoreCase)); } diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp index f6deeb3..b54d625 100644 --- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp +++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp @@ -331,10 +331,10 @@ namespace CalculatorManagerTest Command commands4[] = { Command::Command2, Command::CommandADD, Command::Command3, Command::CommandEQU, Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"7", L"", commands4); + TestDriver::Test(L"7", L"4 + 3=", commands4); Command commands5[] = { Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5); + TestDriver::Test(L"4", L"4=", commands5); Command commands6[] = { Command::Command2, Command::Command5, Command::Command6, Command::CommandSQRT, Command::CommandSQRT, Command::CommandSQRT, Command::CommandNULL }; @@ -342,21 +342,21 @@ namespace CalculatorManagerTest Command commands7[] = { Command::Command3, Command::CommandSUB, Command::Command6, Command::CommandEQU, Command::CommandMUL, Command::Command3, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"-9", L"", commands7); + TestDriver::Test(L"-9", L"-3 \x00D7 3=", commands7); Command commands8[] = { Command::Command9, Command::CommandMUL, Command::Command6, Command::CommandSUB, Command::CommandCENTR, Command::Command8, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"46", L"", commands8); + TestDriver::Test(L"46", L"9 \x00D7 6 - 8=", commands8); Command commands9[] = { Command::Command6, Command::CommandMUL, Command::Command6, Command::CommandPERCENT, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"0.36", L"", commands9); + TestDriver::Test(L"0.36", L"6 \x00D7 0.06=", commands9); Command commands10[] = { Command::Command5, Command::Command0, Command::CommandADD, Command::Command2, Command::Command0, Command::CommandPERCENT, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands10); + TestDriver::Test(L"60", L"50 + 10=", commands10); Command commands11[] = { Command::Command4, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"8", L"", commands11); + TestDriver::Test(L"8", L"4 + 4=", commands11); Command commands12[] = { Command::Command5, Command::CommandADD, Command::CommandMUL, Command::Command3, Command::CommandNULL }; TestDriver::Test(L"3", L"5 \x00D7 ", commands12); @@ -367,7 +367,7 @@ namespace CalculatorManagerTest Command commands14[] = { Command::Command5, Command::Command0, Command::CommandADD, Command::Command2, Command::Command0, Command::CommandPERCENT, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands14); + TestDriver::Test(L"60", L"50 + 10=", commands14); Command commands15[] = { Command::Command0, Command::CommandDIV, Command::Command0, Command::CommandEQU, Command::CommandNULL }; TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands15); @@ -411,10 +411,10 @@ namespace CalculatorManagerTest Command commands4[] = { Command::Command1, Command::CommandADD, Command::Command0, Command::CommandMUL, Command::Command2, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"1", L"", commands4, true, true); + TestDriver::Test(L"1", L"1 + 0 \x00D7 2=", commands4, true, true); Command commands5[] = { Command::Command4, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5, true, true); + TestDriver::Test(L"4", L"4=", commands5, true, true); Command commands6[] = { Command::Command2, Command::Command5, Command::Command6, Command::CommandSQRT, Command::CommandSQRT, Command::CommandSQRT, Command::CommandNULL }; @@ -436,7 +436,7 @@ namespace CalculatorManagerTest TestDriver::Test(L"50.05", L"50 + 1/(20) - ", commands10, true, true); Command commands11[] = { Command::Command4, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"8", L"", commands11, true, true); + TestDriver::Test(L"8", L"4 + 4=", commands11, true, true); Command commands12[] = { Command::Command5, Command::CommandADD, Command::CommandMUL, Command::Command3, Command::CommandNULL }; TestDriver::Test(L"3", L"5 \x00D7 ", commands12, true, true); @@ -447,7 +447,7 @@ namespace CalculatorManagerTest Command commands14[] = { Command::Command5, Command::Command0, Command::CommandADD, Command::Command2, Command::Command0, Command::CommandPERCENT, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"60", L"", commands14, true, true); + TestDriver::Test(L"60", L"50 + 10=", commands14, true, true); Command commands15[] = { Command::Command0, Command::CommandDIV, Command::Command0, Command::CommandEQU, Command::CommandNULL }; TestDriver::Test(L"Result is undefined", L"0 \x00F7 ", commands15, true, true); @@ -642,7 +642,7 @@ namespace CalculatorManagerTest Command commands5[] = { Command::Command2, Command::CommandOPENP, Command::Command2, Command::CommandCLOSEP, Command::CommandADD, Command::CommandEQU, Command::CommandNULL }; - TestDriver::Test(L"4", L"", commands5, true, true); + TestDriver::Test(L"4", L"(2) + 2=", commands5, true, true); } void CalculatorManagerTest::CalculatorManagerTestScientificError()