From a072469b23154966f25f494b2f07a37fde19ef90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lup=C4=8D=C3=ADk?= Date: Mon, 27 Nov 2023 19:39:46 +0100 Subject: [PATCH] Use cursor_timer to tell if a text input is focused. --- Source/Core/Elements/WidgetTextInput.cpp | 7 ++++++- Source/Core/Elements/WidgetTextInput.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Core/Elements/WidgetTextInput.cpp b/Source/Core/Elements/WidgetTextInput.cpp index 04d818b2f..26d91cac0 100644 --- a/Source/Core/Elements/WidgetTextInput.cpp +++ b/Source/Core/Elements/WidgetTextInput.cpp @@ -246,7 +246,7 @@ void WidgetTextInput::Select() void WidgetTextInput::SetSelectionRange(int selection_start, int selection_end) { - if (parent->GetContext()->GetFocusElement() != parent) + if (!IsFocused()) return; const String& value = GetValue(); @@ -382,6 +382,11 @@ Element* WidgetTextInput::GetElement() const return parent; } +bool WidgetTextInput::IsFocused() const +{ + return cursor_timer > 0; +} + void WidgetTextInput::DispatchChangeEvent(bool linebreak) { Dictionary parameters; diff --git a/Source/Core/Elements/WidgetTextInput.h b/Source/Core/Elements/WidgetTextInput.h index d4bb9664c..6fdf8d2b3 100644 --- a/Source/Core/Elements/WidgetTextInput.h +++ b/Source/Core/Elements/WidgetTextInput.h @@ -121,6 +121,9 @@ class WidgetTextInput : public EventListener { /// Gets the parent element containing the widget. Element* GetElement() const; + /// Returns true if the text input element is currently focused. + bool IsFocused() const; + /// Dispatches a change event to the widget's element. void DispatchChangeEvent(bool linebreak = false);