diff --git a/es-core/src/components/TextEditComponent.cpp b/es-core/src/components/TextEditComponent.cpp index a71df9cca..e333a96d0 100644 --- a/es-core/src/components/TextEditComponent.cpp +++ b/es-core/src/components/TextEditComponent.cpp @@ -84,6 +84,22 @@ void TextEditComponent::textInput(const std::string& text) onCursorChanged(); } +std::string TextEditComponent::getValue() const +{ + if (mText.empty()) + return ""; + + // If mText only contains whitespace characters, then return an empty string. + if (std::find_if(mText.cbegin(), mText.cend(), [](char c) { + return !std::isspace(static_cast(c)); + }) == mText.cend()) { + return ""; + } + else { + return mText; + } +} + void TextEditComponent::startEditing() { SDL_StartTextInput(); diff --git a/es-core/src/components/TextEditComponent.h b/es-core/src/components/TextEditComponent.h index 302c832f7..4967880c8 100644 --- a/es-core/src/components/TextEditComponent.h +++ b/es-core/src/components/TextEditComponent.h @@ -33,7 +33,7 @@ public: void onSizeChanged() override; void setValue(const std::string& val) override; - std::string getValue() const override { return mText; } + std::string getValue() const override; void startEditing(); void stopEditing();