From b732e56969940a9c3bbb1b4e09d671005e4a1006 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Fri, 23 May 2014 14:39:53 +0200 Subject: [PATCH] Android: Report current selection to the input method Task-number: QTBUG-39196 Change-Id: Ib798f1de83ccbe3830a746b6ddd435a0934c34cd Reviewed-by: J-P Nurmi Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../android/qandroidinputcontext.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index c2e5f83639..5d47d2fda4 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -472,12 +472,24 @@ void QAndroidInputContext::updateCursorPosition() if (m_composingText.isEmpty() != (m_composingTextStart == -1)) qWarning() << "Input method out of sync" << m_composingText << m_composingTextStart; - - // Qt's idea of the cursor position is the start of the preedit area, so we have to maintain our own preedit cursor pos int realCursorPosition = cursorPos; + int realAnchorPosition = cursorPos; + + int cpos = query->value(Qt::ImCursorPosition).toInt(); + int anchor = query->value(Qt::ImAnchorPosition).toInt(); + if (cpos != anchor) { + if (!m_composingText.isEmpty()) { + qWarning("Selecting text while preediting may give unpredictable results."); + finishComposingText(); + } + int blockPos = getBlockPosition(query); + realCursorPosition = blockPos + cpos; + realAnchorPosition = blockPos + anchor; + } + // Qt's idea of the cursor position is the start of the preedit area, so we maintain our own preedit cursor pos if (!m_composingText.isEmpty()) - realCursorPosition = m_composingCursor; - QtAndroidInput::updateSelection(realCursorPosition, realCursorPosition, //empty selection + realCursorPosition = realAnchorPosition = m_composingCursor; + QtAndroidInput::updateSelection(realCursorPosition, realAnchorPosition, m_composingTextStart, m_composingTextStart + composeLength); // pre-edit text } }