From afc1b2146cc0f809db00e0eebdbb53f742d91044 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Wed, 13 Nov 2019 13:10:05 -0800 Subject: [PATCH] Fix focus for EquationTextBox (#787) --- src/Calculator/Controls/EquationTextBox.cpp | 8 ++++---- src/Calculator/Controls/EquationTextBox.h | 3 ++- .../Views/GraphingCalculator/EquationInputArea.xaml.cpp | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Calculator/Controls/EquationTextBox.cpp b/src/Calculator/Controls/EquationTextBox.cpp index 2fc9a7bee..d4b70f609 100644 --- a/src/Calculator/Controls/EquationTextBox.cpp +++ b/src/Calculator/Controls/EquationTextBox.cpp @@ -142,7 +142,7 @@ void EquationTextBox::OnRichEditBoxTextChanged(Object ^ sender, RoutedEventArgs void EquationTextBox::OnRichEditBoxGotFocus(Object ^ sender, RoutedEventArgs ^ e) { - m_isFocused = true; + m_HasFocus = true; UpdateCommonVisualState(); UpdateDeleteButtonVisualState(); } @@ -151,7 +151,7 @@ void EquationTextBox::OnRichEditBoxLostFocus(Object ^ sender, RoutedEventArgs ^ { if (!m_richEditBox->ContextFlyout->IsOpen) { - m_isFocused = false; + m_HasFocus = false; } UpdateCommonVisualState(); UpdateDeleteButtonVisualState(); @@ -222,7 +222,7 @@ void EquationTextBox::UpdateCommonVisualState() { String ^ state = "Normal"; - if (m_isFocused) + if (m_HasFocus) { state = "Focused"; } @@ -271,5 +271,5 @@ bool EquationTextBox::ShouldDeleteButtonBeVisible() { text = m_richEditBox->MathText; } - return (!text->IsEmpty() && m_isFocused); + return (!text->IsEmpty() && m_HasFocus); } diff --git a/src/Calculator/Controls/EquationTextBox.h b/src/Calculator/Controls/EquationTextBox.h index 1d8c3d7a5..f7e0d8c99 100644 --- a/src/Calculator/Controls/EquationTextBox.h +++ b/src/Calculator/Controls/EquationTextBox.h @@ -22,6 +22,8 @@ namespace CalculatorApp DEPENDENCY_PROPERTY(Windows::UI::Xaml::Media::SolidColorBrush^, EquationColor); DEPENDENCY_PROPERTY(Windows::UI::Xaml::Controls::Flyout^, ColorChooserFlyout); + PROPERTY_R(bool, HasFocus); + event Windows::UI::Xaml::RoutedEventHandler ^ RemoveButtonClicked; event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesButtonClicked; event Windows::UI::Xaml::RoutedEventHandler ^ EquationSubmitted; @@ -64,7 +66,6 @@ namespace CalculatorApp Windows::UI::Xaml::Controls::Button^ m_functionButton; Windows::UI::Xaml::Controls::Primitives::ToggleButton^ m_colorChooserButton; - bool m_isFocused; bool m_isPointerOver; bool m_isColorChooserFlyoutOpen; }; diff --git a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp index 3df6cb7db..483524f12 100644 --- a/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp +++ b/src/Calculator/Views/GraphingCalculator/EquationInputArea.xaml.cpp @@ -87,7 +87,11 @@ void EquationInputArea::InputTextBox_Submitted(Object ^ sender, RoutedEventArgs auto tb = static_cast(sender); auto eq = static_cast(tb->DataContext); eq->Expression = tb->GetEquationText(); - FocusManager::TryMoveFocus(::FocusNavigationDirection::Left); + + if (tb->HasFocus) + { + FocusManager::TryMoveFocus(::FocusNavigationDirection::Left); + } } void EquationInputArea::EquationTextBox_RemoveButtonClicked(Object ^ sender, RoutedEventArgs ^ e)