From 239515366c35708cc9b5e96042285bee67e86fae Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 20 Feb 2025 21:47:49 -0500 Subject: [PATCH] Fix PrefixValidator being too strict --- src/core/validator.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/validator.cpp b/src/core/validator.cpp index b3b36589..f682efc3 100644 --- a/src/core/validator.cpp +++ b/src/core/validator.cpp @@ -10,10 +10,17 @@ bool PrefixValidator::missingPrefix(const QString &input) const { QValidator::State PrefixValidator::validate(QString &input, int &pos) const { auto state = QRegularExpressionValidator::validate(input, pos); - if (state == QValidator::Acceptable) { - // This input could be valid. If there's a prefix we should require it now. - if (missingPrefix(input)) + if (missingPrefix(input)) { + if (state == QValidator::Acceptable) { + // If the input was valid, it should be intermediate because it's missing the prefix. state = QValidator::Intermediate; + } else if (state == QValidator::Invalid) { + // If the input was invalid, we should check if it could become valid once it has the prefix. + QString withPrefix = m_prefix + input; + if (QRegularExpressionValidator::validate(withPrefix, pos) != QValidator::Invalid) { + state = QValidator::Intermediate; + } + } } return state; }