From 21eca49954afb0d98d616d475c1c09ca00606af8 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 9 Dec 2011 11:07:01 +0200 Subject: 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 --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 26 +++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 3bcac62..02bc4d0 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 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 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); } } -- cgit v0.12