diff options
author | Sami Merila <sami.merila@nokia.com> | 2011-10-20 13:46:12 (GMT) |
---|---|---|
committer | Sami Merila <sami.merila@nokia.com> | 2011-10-20 13:46:12 (GMT) |
commit | 2be143ebb5246bb2f9b674bb09d23df5b2b6c504 (patch) | |
tree | 81b4a77a2d571c5230e831f0624fe17bec0a9b15 /src/gui/inputmethod | |
parent | 20542f9546637bd649c928226249be0ffc91841b (diff) | |
download | Qt-2be143ebb5246bb2f9b674bb09d23df5b2b6c504.zip Qt-2be143ebb5246bb2f9b674bb09d23df5b2b6c504.tar.gz Qt-2be143ebb5246bb2f9b674bb09d23df5b2b6c504.tar.bz2 |
Accepting predicted text using hardware keyboard replaces unwanted part
Current implementation of Symbian input context assumes that predicted
word replacement happens so that the original typed text is at the end
of the surrounded text. The logic fails, if to-be-predicted text is
in the middle of, or in the beginning of another, already accepted
word.
As a fix, input context need to store the original cursor position,
when reset() was called (this happens when word selection list
appears). Input context is already storing a copy of a preedit string
in this situation.
Then, when word replacement happens, this stored cursor position is
used instead of current cursor position (the native side might
temporarily move the cursor to the end when word selection list opens
or closes) to replace the typed word with one selected from suggested
word list.
Stored cursor position is dismissed immediately after used, or
if cached preedit string is dismissed.
Task-number: QTBUG-22147
Reviewed-by: Miikka Heikkinen
Diffstat (limited to 'src/gui/inputmethod')
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_p.h | 1 | ||||
-rw-r--r-- | src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 37 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/gui/inputmethod/qcoefepinputcontext_p.h b/src/gui/inputmethod/qcoefepinputcontext_p.h index 8c30838..cefae5e 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_p.h +++ b/src/gui/inputmethod/qcoefepinputcontext_p.h @@ -162,6 +162,7 @@ private: QBasicTimer m_tempPreeditStringTimeout; bool m_hasTempPreeditString; QString m_cachedPreeditString; + int m_cachedCursorAndAnchorPosition; int m_splitViewResizeBy; Qt::WindowStates m_splitViewPreviousWindowStates; diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 79005ce..66ab4c8 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -115,6 +115,7 @@ QCoeFepInputContext::QCoeFepInputContext(QObject *parent) m_formatRetriever(0), m_pointerHandler(0), m_hasTempPreeditString(false), + m_cachedCursorAndAnchorPosition(-1), m_splitViewResizeBy(0), m_splitViewPreviousWindowStates(Qt::WindowNoState) { @@ -158,9 +159,18 @@ void QCoeFepInputContext::reset() } // Store a copy of preedit text, if prediction is active and input context is reseted. // This is to ensure that we can replace preedit string after losing focus to FEP manager's - // internal sub-windows. - if (m_cachedPreeditString.isEmpty() && !(currentHints & Qt::ImhNoPredictiveText)) + // internal sub-windows. Additionally, store the cursor position if there is no selected text. + // This allows input context to replace preedit strings if they are not at the end of current + // text. + if (m_cachedPreeditString.isEmpty() && !(currentHints & Qt::ImhNoPredictiveText)) { m_cachedPreeditString = m_preeditString; + if (focusWidget()) { + int cursor = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt(); + int anchor = focusWidget()->inputMethodQuery(Qt::ImAnchorPosition).toInt(); + if (cursor == anchor) + m_cachedCursorAndAnchorPosition = cursor; + } + } commitCurrentString(true); } @@ -196,6 +206,7 @@ void QCoeFepInputContext::setFocusWidget(QWidget *w) void QCoeFepInputContext::widgetDestroyed(QWidget *w) { m_cachedPreeditString.clear(); + m_cachedCursorAndAnchorPosition = -1; // Make sure that the input capabilities of whatever new widget got focused are queried. CCoeControl *ctrl = w->effectiveWinId(); @@ -981,6 +992,7 @@ void QCoeFepInputContext::StartFepInlineEditL(const TDesC& aInitialInlineText, return; m_cachedPreeditString.clear(); + m_cachedCursorAndAnchorPosition = -1; commitTemporaryPreeditString(); @@ -1039,8 +1051,16 @@ void QCoeFepInputContext::UpdateFepInlineTextL(const TDesC& aNewInlineText, QString newPreeditString = qt_TDesC2QString(aNewInlineText); QInputMethodEvent event(newPreeditString, attributes); if (!m_cachedPreeditString.isEmpty()) { - event.setCommitString(QLatin1String(""), -m_cachedPreeditString.length(), m_cachedPreeditString.length()); + int cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt(); + // Predicted word is either replaced from the end of the word (normal case), + // or from stored location, if the predicted word is either in the beginning of, + // or in the middle of already committed word. + int diff = cursorPos - m_cachedCursorAndAnchorPosition; + int replaceLocation = (diff != m_cachedPreeditString.length()) ? diff : m_cachedPreeditString.length(); + + event.setCommitString(QLatin1String(""), -replaceLocation, m_cachedPreeditString.length()); m_cachedPreeditString.clear(); + m_cachedCursorAndAnchorPosition = -1; } else if (newPreeditString.isEmpty() && m_preeditString.isEmpty()) { // In Symbian world this means "erase last character". event.setCommitString(QLatin1String(""), -1, 1); @@ -1138,6 +1158,10 @@ void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCur int pos = aCursorSelection.iAnchorPos; int length = aCursorSelection.iCursorPos - pos; + if (m_cachedCursorAndAnchorPosition != -1) { + pos = m_cachedCursorAndAnchorPosition; + length = 0; + } QList<QInputMethodEvent::Attribute> attributes; attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos, length, QVariant()); @@ -1155,6 +1179,13 @@ void QCoeFepInputContext::GetCursorSelectionForFep(TCursorSelection& aCursorSele int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size(); int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size(); + + // If the position is stored, use that value, so that word replacement from proposed word + // lists are added to the correct position. + if (m_cachedCursorAndAnchorPosition != -1) { + cursor = m_cachedCursorAndAnchorPosition; + anchor = m_cachedCursorAndAnchorPosition; + } QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>(); int combinedSize = text.size() + m_preeditString.size(); if (combinedSize < anchor || combinedSize < cursor) { |