From 07108af967d9c437fffdd39262fba5652b8219ec Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Thu, 9 Apr 2020 12:24:25 -0700 Subject: [PATCH] Fix crash when using "C" key to clear equation (#1152) * Fix two pane crash on closing window * clearcrash --- .../GraphingCalculator/GraphingNumPad.xaml.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cpp b/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cpp index 67abc0b0..21acda61 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/GraphingNumPad.xaml.cpp @@ -22,7 +22,8 @@ using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; -// Dictionary of the enum of the button clicked mapped to an object with the string to enter into the rich edit, and the start and end of the selection after text has been entered. +// Dictionary of the enum of the button clicked mapped to an object with the string to enter into the rich edit, and the start and end of the selection after +// text has been entered. static const std::unordered_map> buttonOutput = { { NumbersAndOperatorsEnum::Sin, { L"sin()", 4, 0 } }, { NumbersAndOperatorsEnum::Cos, { L"cos()", 4, 0 } }, @@ -224,8 +225,15 @@ void GraphingNumPad::ClearButton_Clicked(Platform::Object ^ /*sender*/, RoutedEv auto mathRichEdit = GetActiveRichEdit(); if (mathRichEdit != nullptr) { - mathRichEdit->MathText = L""; - mathRichEdit->SubmitEquation(CalculatorApp::Controls::EquationSubmissionSource::PROGRAMMATIC); + String ^ text; + mathRichEdit->TextDocument->GetText(Windows::UI::Text::TextGetOptions::NoHidden, &text); + + if (!text->IsEmpty()) + { + mathRichEdit->MathText = L""; + mathRichEdit->SubmitEquation(CalculatorApp::Controls::EquationSubmissionSource::PROGRAMMATIC); + } + TraceLogger::GetInstance()->UpdateButtonUsage(NumbersAndOperatorsEnum::Clear, CalculatorApp::Common::ViewMode::Graphing); } }