mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
Fix issues when users click on the key Equals when the last operation was an unary or if users overrided the previous operation
This commit is contained in:
parent
1eb717f336
commit
fb7d785afc
1 changed files with 18 additions and 4 deletions
|
@ -158,6 +158,12 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||||
{
|
{
|
||||||
unsigned int iValue = static_cast<unsigned int>(wParam - IDC_0);
|
unsigned int iValue = static_cast<unsigned int>(wParam - IDC_0);
|
||||||
|
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
if (!m_bChangeOp)
|
||||||
|
{
|
||||||
|
m_nPrevOpCode = m_nOpCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// this is redundant, illegal keys are disabled
|
// this is redundant, illegal keys are disabled
|
||||||
if (iValue >= static_cast<unsigned int>(m_radix))
|
if (iValue >= static_cast<unsigned int>(m_radix))
|
||||||
{
|
{
|
||||||
|
@ -180,6 +186,8 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||||
// BINARY OPERATORS:
|
// BINARY OPERATORS:
|
||||||
if (IsBinOpCode(wParam))
|
if (IsBinOpCode(wParam))
|
||||||
{
|
{
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
|
||||||
/* Change the operation if last input was operation. */
|
/* Change the operation if last input was operation. */
|
||||||
if (IsBinOpCode(m_nLastCom))
|
if (IsBinOpCode(m_nLastCom))
|
||||||
{
|
{
|
||||||
|
@ -285,13 +293,17 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||||
m_lastVal = m_currentVal;
|
m_lastVal = m_currentVal;
|
||||||
m_nOpCode = (INT)wParam;
|
m_nOpCode = (INT)wParam;
|
||||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode);
|
m_HistoryCollector.AddBinOpToHistory(m_nOpCode);
|
||||||
m_bNoPrevEqu = m_bChangeOp = true;
|
m_bChangeOp = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UNARY OPERATORS:
|
// UNARY OPERATORS:
|
||||||
if (IsUnaryOpCode(wParam) || (wParam == IDC_DEGREES))
|
if (IsUnaryOpCode(wParam) || (wParam == IDC_DEGREES))
|
||||||
{
|
{
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
m_bChangeOp = false;
|
||||||
|
m_nPrevOpCode = m_nOpCode = 0;
|
||||||
|
|
||||||
/* Functions are unary operations. */
|
/* Functions are unary operations. */
|
||||||
/* If the last thing done was an operator, m_currentVal was cleared. */
|
/* If the last thing done was an operator, m_currentVal was cleared. */
|
||||||
/* In that case we better use the number before the operator */
|
/* In that case we better use the number before the operator */
|
||||||
|
@ -476,10 +488,12 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
||||||
{
|
{
|
||||||
m_currentVal = m_holdVal;
|
m_currentVal = m_holdVal;
|
||||||
DisplayNum(); // to update the m_numberString
|
DisplayNum(); // to update the m_numberString
|
||||||
|
if (IsBinOpCode(m_nOpCode))
|
||||||
|
{
|
||||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, false);
|
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, false);
|
||||||
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); // Adding the repeated last op to history
|
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); // Adding the repeated last op to history
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Do the current or last operation.
|
// Do the current or last operation.
|
||||||
m_currentVal = DoOperation(m_nOpCode, m_currentVal, m_lastVal);
|
m_currentVal = DoOperation(m_nOpCode, m_currentVal, m_lastVal);
|
||||||
m_nPrevOpCode = m_nOpCode;
|
m_nPrevOpCode = m_nOpCode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue