Skip to content

Commit 37b8db7

Browse files
author
Qt Continuous Integration System
committed
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-s60-public: Accepting predicted text using hardware keyboard replaces unwanted part
2 parents ac1fcae + 2be143e commit 37b8db7

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/gui/inputmethod/qcoefepinputcontext_p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private Q_SLOTS:
162162
QBasicTimer m_tempPreeditStringTimeout;
163163
bool m_hasTempPreeditString;
164164
QString m_cachedPreeditString;
165+
int m_cachedCursorAndAnchorPosition;
165166

166167
int m_splitViewResizeBy;
167168
Qt::WindowStates m_splitViewPreviousWindowStates;

src/gui/inputmethod/qcoefepinputcontext_s60.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ QCoeFepInputContext::QCoeFepInputContext(QObject *parent)
115115
m_formatRetriever(0),
116116
m_pointerHandler(0),
117117
m_hasTempPreeditString(false),
118+
m_cachedCursorAndAnchorPosition(-1),
118119
m_splitViewResizeBy(0),
119120
m_splitViewPreviousWindowStates(Qt::WindowNoState)
120121
{
@@ -158,9 +159,18 @@ void QCoeFepInputContext::reset()
158159
}
159160
// Store a copy of preedit text, if prediction is active and input context is reseted.
160161
// This is to ensure that we can replace preedit string after losing focus to FEP manager's
161-
// internal sub-windows.
162-
if (m_cachedPreeditString.isEmpty() && !(currentHints & Qt::ImhNoPredictiveText))
162+
// internal sub-windows. Additionally, store the cursor position if there is no selected text.
163+
// This allows input context to replace preedit strings if they are not at the end of current
164+
// text.
165+
if (m_cachedPreeditString.isEmpty() && !(currentHints & Qt::ImhNoPredictiveText)) {
163166
m_cachedPreeditString = m_preeditString;
167+
if (focusWidget()) {
168+
int cursor = focusWidget()->inputMethodQuery(Qt::ImCursorPosition).toInt();
169+
int anchor = focusWidget()->inputMethodQuery(Qt::ImAnchorPosition).toInt();
170+
if (cursor == anchor)
171+
m_cachedCursorAndAnchorPosition = cursor;
172+
}
173+
}
164174
commitCurrentString(true);
165175
}
166176

@@ -196,6 +206,7 @@ void QCoeFepInputContext::setFocusWidget(QWidget *w)
196206
void QCoeFepInputContext::widgetDestroyed(QWidget *w)
197207
{
198208
m_cachedPreeditString.clear();
209+
m_cachedCursorAndAnchorPosition = -1;
199210

200211
// Make sure that the input capabilities of whatever new widget got focused are queried.
201212
CCoeControl *ctrl = w->effectiveWinId();
@@ -981,6 +992,7 @@ void QCoeFepInputContext::StartFepInlineEditL(const TDesC& aInitialInlineText,
981992
return;
982993

983994
m_cachedPreeditString.clear();
995+
m_cachedCursorAndAnchorPosition = -1;
984996

985997
commitTemporaryPreeditString();
986998

@@ -1039,8 +1051,16 @@ void QCoeFepInputContext::UpdateFepInlineTextL(const TDesC& aNewInlineText,
10391051
QString newPreeditString = qt_TDesC2QString(aNewInlineText);
10401052
QInputMethodEvent event(newPreeditString, attributes);
10411053
if (!m_cachedPreeditString.isEmpty()) {
1042-
event.setCommitString(QLatin1String(""), -m_cachedPreeditString.length(), m_cachedPreeditString.length());
1054+
int cursorPos = w->inputMethodQuery(Qt::ImCursorPosition).toInt();
1055+
// Predicted word is either replaced from the end of the word (normal case),
1056+
// or from stored location, if the predicted word is either in the beginning of,
1057+
// or in the middle of already committed word.
1058+
int diff = cursorPos - m_cachedCursorAndAnchorPosition;
1059+
int replaceLocation = (diff != m_cachedPreeditString.length()) ? diff : m_cachedPreeditString.length();
1060+
1061+
event.setCommitString(QLatin1String(""), -replaceLocation, m_cachedPreeditString.length());
10431062
m_cachedPreeditString.clear();
1063+
m_cachedCursorAndAnchorPosition = -1;
10441064
} else if (newPreeditString.isEmpty() && m_preeditString.isEmpty()) {
10451065
// In Symbian world this means "erase last character".
10461066
event.setCommitString(QLatin1String(""), -1, 1);
@@ -1138,6 +1158,10 @@ void QCoeFepInputContext::SetCursorSelectionForFepL(const TCursorSelection& aCur
11381158

11391159
int pos = aCursorSelection.iAnchorPos;
11401160
int length = aCursorSelection.iCursorPos - pos;
1161+
if (m_cachedCursorAndAnchorPosition != -1) {
1162+
pos = m_cachedCursorAndAnchorPosition;
1163+
length = 0;
1164+
}
11411165

11421166
QList<QInputMethodEvent::Attribute> attributes;
11431167
attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, pos, length, QVariant());
@@ -1155,6 +1179,13 @@ void QCoeFepInputContext::GetCursorSelectionForFep(TCursorSelection& aCursorSele
11551179

11561180
int cursor = w->inputMethodQuery(Qt::ImCursorPosition).toInt() + m_preeditString.size();
11571181
int anchor = w->inputMethodQuery(Qt::ImAnchorPosition).toInt() + m_preeditString.size();
1182+
1183+
// If the position is stored, use that value, so that word replacement from proposed word
1184+
// lists are added to the correct position.
1185+
if (m_cachedCursorAndAnchorPosition != -1) {
1186+
cursor = m_cachedCursorAndAnchorPosition;
1187+
anchor = m_cachedCursorAndAnchorPosition;
1188+
}
11581189
QString text = w->inputMethodQuery(Qt::ImSurroundingText).value<QString>();
11591190
int combinedSize = text.size() + m_preeditString.size();
11601191
if (combinedSize < anchor || combinedSize < cursor) {

0 commit comments

Comments
 (0)