diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-09-13 01:59:26 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-09-13 15:36:34 +0000 |
commit | 45c1473847ad65c4d43f9a605a86439867442883 (patch) | |
tree | ca90faef5601df2f5fcbed0151781efbe89e4fdb | |
parent | bff307ab93bd6963f84e08e8050efa6a838dba6e (diff) |
Detect when we are at the sentence boundary
On Samsung devices this would cause it to always to captalize each word
even if it was not a new sentence. Therefore we use QTextBoundaryFinder
to determine if it is a new sentence or not.
Task-number: QTBUG-69398
Task-number: QTBUG-66531
Change-Id: I24bf36f09a2570acfefd4343551cb1720ddc6279
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index f548a1fa96..c46a435db1 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -58,6 +58,7 @@ #include <private/qhighdpiscaling_p.h> #include <QTextCharFormat> +#include <QTextBoundaryFinder> #include <QDebug> @@ -892,8 +893,19 @@ jint QAndroidInputContext::getCursorCapsMode(jint /*reqModes*/) return res; const uint qtInputMethodHints = query->value(Qt::ImHints).toUInt(); - - if (!(qtInputMethodHints & Qt::ImhLowercaseOnly) && !(qtInputMethodHints & Qt::ImhNoAutoUppercase)) + const int localPos = query->value(Qt::ImCursorPosition).toInt(); + + bool atWordBoundary = (localPos == 0); + if (!atWordBoundary) { + QString surroundingText = query->value(Qt::ImSurroundingText).toString(); + surroundingText.truncate(localPos); + // Add a character to see if it is at the end of the sentence or not + QTextBoundaryFinder finder(QTextBoundaryFinder::Sentence, surroundingText + QLatin1Char('A')); + finder.setPosition(localPos); + if (finder.isAtBoundary()) + atWordBoundary = finder.isAtBoundary(); + } + if (atWordBoundary && !(qtInputMethodHints & Qt::ImhLowercaseOnly) && !(qtInputMethodHints & Qt::ImhNoAutoUppercase)) res |= CAP_MODE_SENTENCES; if (qtInputMethodHints & Qt::ImhUppercaseOnly) |