aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannu Koivisto <hannu.koivisto@vincit.fi>2010-09-14 15:31:06 +0300
committerPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-09-15 15:19:20 +0300
commit4cc2bf81f2e7e9a1e50b22fa2c7efa57d4547f24 (patch)
treec151138f51d3d4075224a5047dcf9e05eb8e366d
parent813e63a214fb79f3428a562763e2bbcb9e61e8a9 (diff)
Fixes: MTextEdit / select all -> input context notification
RevBy: Pekka Vuorela Details: call updateMicroFocus so that the input context can inform the input method about updated selection status.
-rwxr-xr-xsrc/corelib/widgets/mtextedit.cpp3
-rw-r--r--tests/ut_mtextedit/ut_mtextedit.cpp41
-rw-r--r--tests/ut_mtextedit/ut_mtextedit.h1
3 files changed, 45 insertions, 0 deletions
diff --git a/src/corelib/widgets/mtextedit.cpp b/src/corelib/widgets/mtextedit.cpp
index 6cfc24bc..3182054e 100755
--- a/src/corelib/widgets/mtextedit.cpp
+++ b/src/corelib/widgets/mtextedit.cpp
@@ -1946,6 +1946,7 @@ void MTextEdit::handleMouseMove(int cursorPosition, QGraphicsSceneMouseEvent *ev
void MTextEdit::selectAll()
{
Q_D(MTextEdit);
+ d->disableUpdateMicroFocus();
d->commitPreedit();
d->cursor()->setPosition(0);
@@ -1960,7 +1961,9 @@ void MTextEdit::selectAll()
model()->updateCursor();
emit selectionChanged();
d->sendCopyAvailable(true);
+ d->updateMicroFocus();
}
+ d->enableUpdateMicroFocus(true);
}
diff --git a/tests/ut_mtextedit/ut_mtextedit.cpp b/tests/ut_mtextedit/ut_mtextedit.cpp
index 8521500f..906e694b 100644
--- a/tests/ut_mtextedit/ut_mtextedit.cpp
+++ b/tests/ut_mtextedit/ut_mtextedit.cpp
@@ -2089,6 +2089,47 @@ void Ut_MTextEdit::testSelectByArrowKeys()
QVERIFY(!m_sic->selectionAvailableAtLastUpdate);
}
+void Ut_MTextEdit::testSelectAll()
+{
+ QSignalSpy copyAvailableSpy(m_subject.get(), SIGNAL(copyAvailable(bool)));
+ QVERIFY(copyAvailableSpy.isValid());
+
+ QSignalSpy selectionChangedSpy(m_subject.get(), SIGNAL(selectionChanged()));
+ QVERIFY(selectionChangedSpy.isValid());
+
+ setupSipEnv(m_subject.get());
+
+ // Case 1, text and pre-edit
+ m_subject->setText("fish ");
+ // Pre-edit should be committed, yet that shouldn't cause extra
+ // QInputContext::update() calls
+ QInputMethodEvent preeditEvent("salmon", QList<QInputMethodEvent::Attribute>());
+ m_subject->inputMethodEvent(&preeditEvent);
+
+ QKeyEvent selectAll(QEvent::KeyPress, Qt::Key_A, Qt::ControlModifier, QChar('a'));
+ m_sic->updateCallCount = 0;
+ m_subject->keyPressEvent(&selectAll);
+ QCOMPARE(m_sic->updateCallCount, 1);
+ QVERIFY(m_sic->selectionAvailableAtLastUpdate);
+ QCOMPARE(copyAvailableSpy.count(), 1);
+ QCOMPARE(copyAvailableSpy.first().count(), 1);
+ QVERIFY(copyAvailableSpy.first().first() == true);
+ QCOMPARE(selectionChangedSpy.count(), 1);
+ QCOMPARE(m_sic->selectedTextAtLastUpdate, QString("fish salmon"));
+ QCOMPARE(m_subject->cursorPosition(), m_sic->selectedTextAtLastUpdate.length());
+
+ // Case 2, no text
+ m_subject->setText("");
+ copyAvailableSpy.clear();
+ selectionChangedSpy.clear();
+
+ m_sic->updateCallCount = 0;
+ m_subject->keyPressEvent(&selectAll);
+ QCOMPARE(m_sic->updateCallCount, 0);
+ QCOMPARE(copyAvailableSpy.count(), 0);
+ QCOMPARE(selectionChangedSpy.count(), 0);
+}
+
void Ut_MTextEdit::testAutoSipEnabled()
{
MTextEdit *subject = new MTextEdit;
diff --git a/tests/ut_mtextedit/ut_mtextedit.h b/tests/ut_mtextedit/ut_mtextedit.h
index 2c2aa9f3..586c512b 100644
--- a/tests/ut_mtextedit/ut_mtextedit.h
+++ b/tests/ut_mtextedit/ut_mtextedit.h
@@ -127,6 +127,7 @@ private slots:
void testArrowKeys();
void testSelectByArrowKeys();
+ void testSelectAll();
void testAutoSipEnabled();
void testAutoSipDisabled();