summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 09:16:56 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-05-27 09:17:14 +0200
commit761b71bd20524bc1e495508a52c38a0bc6679a06 (patch)
treedf2748fb11234c9b0dfb82828ce8d76459d185db /src/plugins/platforms/android
parent800941df899a4418d4ac6cebbcc31a40120167bc (diff)
parent14aa1f7d6ffea29647557f98e654355782f55e66 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r--src/plugins/platforms/android/qandroidinputcontext.cpp79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp
index 07a6b52dbe..db40c30d7d 100644
--- a/src/plugins/platforms/android/qandroidinputcontext.cpp
+++ b/src/plugins/platforms/android/qandroidinputcontext.cpp
@@ -1129,46 +1129,63 @@ QString QAndroidInputContext::getSelectedText(jint /*flags*/)
QString QAndroidInputContext::getTextAfterCursor(jint length, jint /*flags*/)
{
- //### the preedit text could theoretically be after the cursor
- QVariant textAfter = QInputMethod::queryFocusObject(Qt::ImTextAfterCursor, QVariant(length));
- if (textAfter.isValid()) {
- return textAfter.toString().left(length);
- }
-
- //compatibility code for old controls that do not implement the new API
- QSharedPointer<QInputMethodQueryEvent> query = focusObjectInputMethodQuery();
- if (query.isNull())
+ if (length <= 0)
return QString();
- QString text = query->value(Qt::ImSurroundingText).toString();
- if (!text.length())
- return text;
+ QString text;
- int cursorPos = query->value(Qt::ImCursorPosition).toInt();
- return text.mid(cursorPos, length);
+ QVariant reportedTextAfter = QInputMethod::queryFocusObject(Qt::ImTextAfterCursor, length);
+ if (reportedTextAfter.isValid()) {
+ text = reportedTextAfter.toString();
+ } else {
+ // Compatibility code for old controls that do not implement the new API
+ QSharedPointer<QInputMethodQueryEvent> query =
+ focusObjectInputMethodQuery(Qt::ImCursorPosition | Qt::ImSurroundingText);
+ if (query) {
+ const int cursorPos = query->value(Qt::ImCursorPosition).toInt();
+ text = query->value(Qt::ImSurroundingText).toString().mid(cursorPos);
+ }
+ }
+
+ // Controls do not report preedit text, so we have to add it
+ if (!m_composingText.isEmpty()) {
+ const int cursorPosInsidePreedit = m_composingCursor - m_composingTextStart;
+ text = m_composingText.midRef(cursorPosInsidePreedit) + text;
+ }
+
+ text.truncate(length);
+ return text;
}
QString QAndroidInputContext::getTextBeforeCursor(jint length, jint /*flags*/)
{
- QVariant textBefore = QInputMethod::queryFocusObject(Qt::ImTextBeforeCursor, QVariant(length));
- if (textBefore.isValid())
- return textBefore.toString().rightRef(length) + m_composingText;
-
- //compatibility code for old controls that do not implement the new API
- QSharedPointer<QInputMethodQueryEvent> query = focusObjectInputMethodQuery();
- if (query.isNull())
+ if (length <= 0)
return QString();
- int cursorPos = query->value(Qt::ImCursorPosition).toInt();
- QString text = query->value(Qt::ImSurroundingText).toString();
- if (!text.length())
- return text;
+ QString text;
- //### the preedit text does not need to be immediately before the cursor
- if (cursorPos <= length)
- return text.leftRef(cursorPos) + m_composingText;
- else
- return text.midRef(cursorPos - length, length) + m_composingText;
+ QVariant reportedTextBefore = QInputMethod::queryFocusObject(Qt::ImTextBeforeCursor, length);
+ if (reportedTextBefore.isValid()) {
+ text = reportedTextBefore.toString();
+ } else {
+ // Compatibility code for old controls that do not implement the new API
+ QSharedPointer<QInputMethodQueryEvent> query =
+ focusObjectInputMethodQuery(Qt::ImCursorPosition | Qt::ImSurroundingText);
+ if (query) {
+ const int cursorPos = query->value(Qt::ImCursorPosition).toInt();
+ text = query->value(Qt::ImSurroundingText).toString().left(cursorPos);
+ }
+ }
+
+ // Controls do not report preedit text, so we have to add it
+ if (!m_composingText.isEmpty()) {
+ const int cursorPosInsidePreedit = m_composingCursor - m_composingTextStart;
+ text += m_composingText.leftRef(cursorPosInsidePreedit);
+ }
+
+ if (text.length() > length)
+ text = text.right(length);
+ return text;
}
/*
@@ -1231,6 +1248,8 @@ jboolean QAndroidInputContext::setComposingRegion(jint start, jint end)
if (query.isNull())
return JNI_FALSE;
+ if (start == end)
+ return JNI_TRUE;
if (start > end)
qSwap(start, end);