aboutsummaryrefslogtreecommitdiffstats
path: root/src/virtualkeyboard/shadowinputcontext.cpp
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2023-02-01 09:33:38 +0200
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2023-02-08 16:14:43 +0200
commit960304256ece1ab019eeab91697317b1abf303ae (patch)
treed9e5f6c228271ab61107f1f50a399e27ab0a6484 /src/virtualkeyboard/shadowinputcontext.cpp
parentbbe47df8c8f89434c534eca032e88160ed05374e (diff)
Fix pre-edit text on shadow input when reselecting the first word
The shadow input control did not receive pre-edit text when the first word was reselected. In this case, the text is transferred from the input field to pre-edit field. Analysis shows that QInputMethodEvent::Selection cannot be used together when complete text buffer is replaced. This is because of quirks found in QQuickTextInput's processInputMethodEvent. Fix by handling text replacement and selection as separate events. Pick-to: 6.5 6.4 Change-Id: I2f730a491685e55ff28a98a4929a1cd1b5bf0e6a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Inho Lee <inho.lee@qt.io>
Diffstat (limited to 'src/virtualkeyboard/shadowinputcontext.cpp')
-rw-r--r--src/virtualkeyboard/shadowinputcontext.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/virtualkeyboard/shadowinputcontext.cpp b/src/virtualkeyboard/shadowinputcontext.cpp
index 72c0c90f..808cb8b0 100644
--- a/src/virtualkeyboard/shadowinputcontext.cpp
+++ b/src/virtualkeyboard/shadowinputcontext.cpp
@@ -176,22 +176,28 @@ void ShadowInputContext::update(Qt::InputMethodQueries queries)
const int newCursorPosition = d->inputContext->cursorPosition();
const int newAnchorPosition = d->inputContext->anchorPosition();
+ const QString newPreeditText = d->inputContext->preeditText();
+ const QList<QInputMethodEvent::Attribute> newPreeditAttributes = d->inputContext->preeditTextAttributes();
+
bool updateSurroundingText = newSurroundingText != surroundingText;
bool updateSelection = newCursorPosition != cursorPosition || newAnchorPosition != anchorPosition;
+ if (updateSurroundingText) {
+ QInputMethodEvent inputEvent;
+ inputEvent.setCommitString(newSurroundingText, -cursorPosition, surroundingText.size());
+ QGuiApplication::sendEvent(d->inputItem, &inputEvent);
+ }
+
if (updateSurroundingText || updateSelection) {
QList<QInputMethodEvent::Attribute> attributes;
attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection,
newAnchorPosition,
newCursorPosition - newAnchorPosition, QVariant()));
QInputMethodEvent inputEvent(QString(), attributes);
- if (updateSurroundingText)
- inputEvent.setCommitString(newSurroundingText, -cursorPosition, surroundingText.size());
QGuiApplication::sendEvent(d->inputItem, &inputEvent);
}
- const QString newPreeditText = d->inputContext->preeditText();
- const QList<QInputMethodEvent::Attribute> newPreeditAttributes = d->inputContext->preeditTextAttributes();
- if (d->preeditText != newPreeditText || d->preeditTextAttributes != newPreeditAttributes) {
+ const bool forcePreeditText = !newPreeditText.isEmpty() && (updateSurroundingText || updateSelection);
+ if (forcePreeditText || d->preeditText != newPreeditText || d->preeditTextAttributes != newPreeditAttributes) {
d->preeditText = newPreeditText;
d->preeditTextAttributes = newPreeditAttributes;
QInputMethodEvent inputEvent(d->preeditText, d->preeditTextAttributes);