Skip to content

Commit

Permalink
Use cursor_timer to tell if a text input is focused.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnCZek committed Nov 27, 2023
1 parent 90756db commit a072469
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/Core/Elements/WidgetTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Elements/WidgetTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit a072469

Please sign in to comment.