Skip to content

Commit

Permalink
Ignore selection range update when the element is not focused (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnCZek authored Nov 27, 2023
1 parent d131274 commit 61d1a4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Source/Core/Elements/WidgetTextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ void WidgetTextInput::Select()

void WidgetTextInput::SetSelectionRange(int selection_start, int selection_end)
{
if (!IsFocused())
return;

const String& value = GetValue();
const int byte_start = ConvertCharacterOffsetToByteOffset(value, selection_start);
const int byte_end = ConvertCharacterOffsetToByteOffset(value, selection_end);
Expand Down Expand Up @@ -379,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 61d1a4b

Please sign in to comment.