[Android] Request cursor to be in proper position
Cursor were set to incorrect position (-1) causing first character overwrite in password field, fixed by setting position to '0' for the first character Fixes: QTBUG-85090 Pick-to: 5.15 Change-Id: Ia2333803d5fe8f274f1ad1a643e4ff5aa8556b81 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>bb10
parent
342cc61d3e
commit
2ff546e030
|
|
@ -1409,16 +1409,25 @@ jboolean QAndroidInputContext::setComposingText(const QString &text, jint newCur
|
|||
const int absoluteCursorPos = getAbsoluteCursorPosition(query);
|
||||
int absoluteAnchorPos = getBlockPosition(query) + query->value(Qt::ImAnchorPosition).toInt();
|
||||
|
||||
auto setCursorPosition = [=]() {
|
||||
const int cursorPos = query->value(Qt::ImCursorPosition).toInt();
|
||||
QInputMethodEvent event({}, { { QInputMethodEvent::Selection, cursorPos, 0 } });
|
||||
QGuiApplication::sendEvent(m_focusObject, &event);
|
||||
};
|
||||
|
||||
// If we have composing region and selection (and therefore focusObjectIsComposing() == false),
|
||||
// we must clear selection so that we won't delete it when we will be replacing composing text
|
||||
if (!m_composingText.isEmpty() && absoluteCursorPos != absoluteAnchorPos) {
|
||||
const int cursorPos = query->value(Qt::ImCursorPosition).toInt();
|
||||
QInputMethodEvent event({}, { { QInputMethodEvent::Selection, cursorPos, 0 } });
|
||||
QGuiApplication::sendEvent(m_focusObject, &event);
|
||||
|
||||
setCursorPosition();
|
||||
absoluteAnchorPos = absoluteCursorPos;
|
||||
}
|
||||
|
||||
// The value of Qt::ImCursorPosition is not updated at the start
|
||||
// when the first character is added, so we must update it (QTBUG-85090)
|
||||
if (absoluteCursorPos == 0 && text.length() == 1 && getTextAfterCursor(1,1).length() >= 0) {
|
||||
setCursorPosition();
|
||||
}
|
||||
|
||||
// If we had no composing region, pretend that we had a zero-length composing region at current
|
||||
// cursor position to simplify code. Also account for that we must delete selected text if there
|
||||
// (still) is any.
|
||||
|
|
|
|||
Loading…
Reference in New Issue