summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2011-12-09 11:07:01 +0200
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2011-12-09 11:22:36 +0200
commit21eca49954afb0d98d616d475c1c09ca00606af8 (patch)
tree959ae68ff7144678f316d871133a702debe6519a
parent8ed37d9bba6e2899724d13bd3ba8911c505b1c8c (diff)
downloadqt4-tools-21eca49954afb0d98d616d475c1c09ca00606af8.tar.gz
Symbian: Fix double deletion of selected text when using predictive
The selected text replacement was done incorrectly, leading to removal of additional text equal to the lenght of the original selection. Fixed by not doing any explicit replacement, but instead faking a preedit character that is immediately removed, which triggers selected text removal in the input method handling of the underlying edit control. Task-number: ou1cimx1#938665 Reviewed-by: Sami Merila
-rw-r--r--src/gui/inputmethod/qcoefepinputcontext_s60.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp
index 3bcac62f20..02bc4d0b3b 100644
--- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp
+++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp
@@ -1388,15 +1388,25 @@ void QCoeFepInputContext::StartFepInlineEditL(const TDesC& aInitialInlineText,
// but FEP requires that selected text is always removed at StartFepInlineEditL.
// Let's remove the selected text if aInitialInlineText is empty and there is selected text
if (m_preeditString.isEmpty()) {
- int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt();
- int cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
- int replacementLength = qAbs(cursorPos-anchor);
- if (replacementLength > 0) {
- int replacementStart = cursorPos < anchor ? 0 : -replacementLength;
- QList<QInputMethodEvent::Attribute> clearSelectionAttributes;
- QInputMethodEvent clearSelectionEvent(QLatin1String(""), clearSelectionAttributes);
- clearSelectionEvent.setCommitString(QLatin1String(""), replacementStart, replacementLength);
+ QString currentSelection = w->inputMethodQuery(Qt::ImCurrentSelection).toString();
+ if (!currentSelection.isEmpty()) {
+ // To correctly remove selection in cases where we have multiple lines selected,
+ // we must rely on the control's own selection removal mechanism, as surrounding
+ // text contains only one line. It's also impossible to accurately detect
+ // these overselection cases as the anchor and cursor positions are limited to the
+ // surrounding text.
+ // Solution is to clear the selection by faking a preedit. Use a dummy character
+ // from the current selection just to be safe.
+ QString dummyText = currentSelection.left(1);
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent clearSelectionEvent(dummyText, attributes);
+ clearSelectionEvent.setCommitString(QLatin1String(""), 0, 0);
sendEvent(clearSelectionEvent);
+
+ // Now that selection is taken care of, clear the fake preedit.
+ QInputMethodEvent clearPreeditEvent(QLatin1String(""), attributes);
+ clearPreeditEvent.setCommitString(QLatin1String(""), 0, 0);
+ sendEvent(clearPreeditEvent);
}
}