Skip to content

Commit

Permalink
Detect when we are at the sentence boundary
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
  • Loading branch information
AndyShawQt committed Sep 13, 2018
1 parent bff307a commit 45c1473
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/plugins/platforms/android/qandroidinputcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <private/qhighdpiscaling_p.h>

#include <QTextCharFormat>
#include <QTextBoundaryFinder>

#include <QDebug>

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 45c1473

Please sign in to comment.