Do not hide expression when user presses Enter or = (#695)
* #653 Do not hide expression on EQU operation * #653 Clear expression, when user makes an action * #653 Fixed UI tests * #653 Review fixes
This commit is contained in:
parent
b97046ad67
commit
bfa5f81ef6
@ -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<CalculatorVector<std::pair<std::wstring, int>>>(), std::make_shared<CalculatorVector<std::shared_ptr<IExpressionCommand>>>());
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -82,6 +82,15 @@ void CCalcEngine::ClearTemporaryValues()
|
||||
m_bError = false;
|
||||
}
|
||||
|
||||
void CCalcEngine::ClearDisplay()
|
||||
{
|
||||
if (nullptr != m_pCalcDisplay)
|
||||
{
|
||||
m_pCalcDisplay->SetExpressionDisplay(
|
||||
make_shared<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>());
|
||||
}
|
||||
}
|
||||
|
||||
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<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>());
|
||||
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<CalculatorVector<pair<wstring, int>>>(), make_shared<CalculatorVector<shared_ptr<IExpressionCommand>>>());
|
||||
}
|
||||
m_HistoryCollector.CompleteEquation(groupedString);
|
||||
}
|
||||
|
||||
m_bChangeOp = false;
|
||||
|
@ -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<TType> m_vector;
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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<IExpressionCommand>& spCommand);
|
||||
void UpdateHistoryExpression(uint32_t radix, int32_t precision);
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user