if (oldActiveFocusItem) {
#ifndef QT_NO_IM
- qApp->inputMethod()->reset();
+ qApp->inputMethod()->commit();
#endif
activeFocusItem = 0;
Q_ASSERT(oldActiveFocusItem);
#ifndef QT_NO_IM
- qApp->inputMethod()->reset();
+ qApp->inputMethod()->commit();
#endif
activeFocusItem = 0;
case QEvent::WindowDeactivate:
rootItem()->windowDeactivateEvent();
break;
+ case QEvent::FocusAboutToChange:
+ if (d->activeFocusItem)
+ qGuiApp->inputMethod()->commit();
+ break;
default:
break;
}
}
}
layout->setAdditionalFormats(overrides);
- tentativeCommit = e->tentativeCommitString();
cursor.endEditBlock();
if (e->gotFocus()) {
setBlinkingCursorEnabled(interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard));
} else {
- commitPreedit();
setBlinkingCursorEnabled(false);
if (cursorIsFocusIndicator
if (!isPreediting())
return;
- cursor.beginEditBlock();
- qApp->inputMethod()->reset();
+ qApp->inputMethod()->commit();
- if (!tentativeCommit.isEmpty()) {
- cursor.insertText(tentativeCommit);
- tentativeCommit.clear();
- }
+ if (!isPreediting())
+ return;
+ cursor.beginEditBlock();
preeditCursor = 0;
QTextBlock block = cursor.block();
QTextLayout *layout = block.layout();
QString QQuickTextControl::toPlainText() const
{
- Q_D(const QQuickTextControl);
- QString plainText = document()->toPlainText();
- if (!d->tentativeCommit.isEmpty())
- plainText.insert(textCursor().position(), d->tentativeCommit);
- return plainText;
+ return document()->toPlainText();
}
#ifndef QT_NO_TEXTHTMLPARSER
QString QQuickTextControl::toHtml() const
{
- // note: currently not including tentative commit
return document()->toHtml();
}
#endif
QTextCursor cursor;
QTextCursor selectedWordOnDoubleClick;
QTextCursor selectedBlockOnTrippleClick;
- QString tentativeCommit;
QString highlightedAnchor; // Anchor below cursor
QString anchorOnMousePress;
QString linkToCopy;
Q_D(const QQuickTextInput);
QString content = d->m_text;
- if (!d->m_tentativeCommit.isEmpty())
- content.insert(d->m_cursor, d->m_tentativeCommit);
QString res = d->m_maskData ? d->stripString(content) : content;
return (res.isNull() ? QString::fromLatin1("") : res);
}
return;
if (d->composeMode())
qApp->inputMethod()->reset();
- d->m_tentativeCommit.clear();
d->internalSetText(s, -1, false);
}
}
if (!hasFocus) {
- d->commitPreedit();
if (!d->persistentSelection)
d->deselect();
disconnect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
/*!
\internal
-
- Exits preedit mode and commits parts marked as tentative commit
*/
void QQuickTextInputPrivate::commitPreedit()
{
if (!composeMode())
return;
- qApp->inputMethod()->reset();
+ qApp->inputMethod()->commit();
- if (!m_tentativeCommit.isEmpty()) {
- internalInsert(m_tentativeCommit);
- m_tentativeCommit.clear();
- finishChange(-1, true/*not used, not documented*/, false);
- }
+ if (!composeMode())
+ return;
m_preeditCursor = 0;
m_textLayout.setPreeditArea(-1, QString());
q->updateCursorRectangle();
}
- bool tentativeCommitChanged = m_tentativeCommit != event->tentativeCommitString();
-
- if (tentativeCommitChanged) {
- m_textDirty = true;
- m_tentativeCommit = event->tentativeCommitString();
- }
-
- if (isGettingInput || tentativeCommitChanged)
+ if (isGettingInput)
finishChange(priorState);
if (selectionChange) {
return true;
}
m_cursor = cursorCopy;
-
- if (!m_tentativeCommit.isEmpty()) {
- textCopy.insert(m_cursor, m_tentativeCommit);
- bool validInput = m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid;
- if (!validInput)
- m_tentativeCommit.clear();
- }
- } else {
- m_tentativeCommit.clear();
}
}
#endif
QString m_text;
QString m_inputMask;
QString m_cancelText;
- QString m_tentativeCommit;
QFont font;
QFont sourceFont;
QQuickTextEditPrivate *editPrivate = static_cast<QQuickTextEditPrivate*>(QQuickItemPrivate::get(edit));
QCOMPARE(editPrivate->text, QString("Hello world!"));
- // test that tentative commit is included in text property
- edit->setText("");
- spy.clear();
- QList<QInputMethodEvent::Attribute> attributes;
- QInputMethodEvent event2("preedit", attributes);
- event2.setTentativeCommitString("string");
- QGuiApplication::sendEvent(qGuiApp->focusObject(), &event2);
- QCOMPARE(spy.count(), 1);
- QCOMPARE(edit->text(), QString("string"));
-
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
QGuiApplication::sendEvent(qGuiApp->focusObject(), &queryEvent);
QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), true);
QCOMPARE(input->text(), QString("Our Goodbye world!"));
QCOMPARE(input->cursorPosition(), 7);
- // test that basic tentative commit gets to text property on preedit state
- input->setText("");
- QList<QInputMethodEvent::Attribute> attributes;
- QInputMethodEvent preeditEvent("test", attributes);
- preeditEvent.setTentativeCommitString("test");
- QGuiApplication::sendEvent(input, &preeditEvent);
- QCOMPARE(input->text(), QString("test"));
-
- // tentative commit not allowed present in surrounding text
- QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText);
- QGuiApplication::sendEvent(input, &queryEvent);
- QCOMPARE(queryEvent.value(Qt::ImSurroundingText).toString(), QString(""));
-
- // if text with tentative commit does not validate, not allowed to be part of text property
- input->setText(""); // ensure input state is reset
- QValidator *validator = new QIntValidator(0, 100);
- input->setValidator(validator);
- QGuiApplication::sendEvent(input, &preeditEvent);
- QCOMPARE(input->text(), QString(""));
- input->setValidator(0);
- delete validator;
-
// input should reset selection even if replacement parameters are out of bounds
input->setText("text");
input->setCursorPosition(0);