Emit selectionChanged signals when input method alters the selection.
Check if the input method removes the selection and force emit selectionChanged if it sets a new selection. Task-number: QTBUG-19727 Reviewed-by: Martin Jones Change-Id: Ic8ea1044d0917aac4e52368f431ac9e5c7db7c56 Reviewed-on: http://codereview.qt.nokia.com/2076 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
This commit is contained in:
parent
ef2384ad57
commit
ac22379a75
@ -1918,6 +1918,7 @@ void QTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
|
||||
bool isGettingInput = !e->commitString().isEmpty()
|
||||
|| e->preeditString() != cursor.block().layout()->preeditAreaText()
|
||||
|| e->replacementLength() > 0;
|
||||
bool forceSelectionChanged = false;
|
||||
|
||||
cursor.beginEditBlock();
|
||||
if (isGettingInput) {
|
||||
@ -1941,6 +1942,7 @@ void QTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
|
||||
cursor.setPosition(blockStart + a.length, QTextCursor::KeepAnchor);
|
||||
q->ensureCursorVisible();
|
||||
repaintOldAndNewSelection(oldCursor);
|
||||
forceSelectionChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1974,6 +1976,7 @@ void QTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
|
||||
cursor.d->setX();
|
||||
if (oldPreeditCursor != preeditCursor)
|
||||
emit q->microFocusChanged();
|
||||
selectionChanged(forceSelectionChanged);
|
||||
}
|
||||
|
||||
QVariant QTextControl::inputMethodQuery(Qt::InputMethodQuery property) const
|
||||
|
@ -207,6 +207,8 @@ private slots:
|
||||
void bidiLogicalMovement_data();
|
||||
void bidiLogicalMovement();
|
||||
|
||||
void inputMethodSelection();
|
||||
|
||||
private:
|
||||
void createSelection();
|
||||
int blockCount() const;
|
||||
@ -2365,5 +2367,30 @@ void tst_QTextEdit::bidiLogicalMovement()
|
||||
} while (moved && i >= 0);
|
||||
}
|
||||
|
||||
void tst_QTextEdit::inputMethodSelection()
|
||||
{
|
||||
ed->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
|
||||
|
||||
QSignalSpy selectionSpy(ed, SIGNAL(selectionChanged()));
|
||||
QTextCursor cursor = ed->textCursor();
|
||||
cursor.setPosition(0);
|
||||
cursor.setPosition(5, QTextCursor::KeepAnchor);
|
||||
ed->setTextCursor(cursor);
|
||||
|
||||
QCOMPARE(selectionSpy.count(), 1);
|
||||
QCOMPARE(ed->textCursor().selectionStart(), 0);
|
||||
QCOMPARE(ed->textCursor().selectionEnd(), 5);
|
||||
|
||||
QList<QInputMethodEvent::Attribute> attributes;
|
||||
attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 12, 5, QVariant());
|
||||
QInputMethodEvent event("", attributes);
|
||||
QApplication::sendEvent(ed, &event);
|
||||
|
||||
QCOMPARE(selectionSpy.count(), 2);
|
||||
QCOMPARE(ed->textCursor().selectionStart(), 12);
|
||||
QCOMPARE(ed->textCursor().selectionEnd(), 17);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QTextEdit)
|
||||
#include "tst_qtextedit.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user