TextEditComponent will now return an empty string if only whitespace characters were entered.

This commit is contained in:
Leon Styhre 2021-09-21 22:18:18 +02:00
parent 527b9321b5
commit fc08a83fa0
2 changed files with 17 additions and 1 deletions

View file

@ -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<unsigned char>(c));
}) == mText.cend()) {
return "";
}
else {
return mText;
}
}
void TextEditComponent::startEditing()
{
SDL_StartTextInput();

View file

@ -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();