diff options
author | Graham Coleman <ravelite@gmail.com> | 2013-11-16 08:26:53 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-21 18:30:05 +0100 |
commit | 92b2275c3d4bea4091057b9994d502dbdb64d28b (patch) | |
tree | e34c33d61e378deecdcf731131cff2c36d0248aa /tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp | |
parent | cd91d8ad0281c984a01b8091696a6fdfdfa69514 (diff) |
remove finishEdit() call, fix double textChanged on delete
There is a known bug where duplicate textChanged signals are
triggered on backspace/delete. The bug has been seen on Windows,
Mac, and Linux. Gabi showed that this duplicate signal is caused by
two calls to finishEdit(), one direct and one nested,
in QTextCursorPrivate::remove().
To attempt a fix, I removed the direct call and do not change the
nested call. This change only affects text buffers when they
receive remove commands.
This seems to fix the problem, shown by the test project
uploaded to the bug tracker and also in countTextChangedOnRemove
in tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp.
Further analysis of finishEdit() and QTextCursorPrivate::remove():
finishEdit() calls signals contentsChanged() as long as a valid block
is being edited. Remove() calls finishEdit for all non-table edits,
so finishEdit will be called for most cases.
Methods in the public QTextCursor all seem to set adjusted_anchor
and anchor, none reading it directly, so I haven't found publicly
observable consequences to "adjusted_anchor = anchor = position;".
Task-number: QTBUG-15003
Change-Id: Ic35f25ee81c4007867b47cd8be03c146a673f86d
Reviewed-by: Graham Coleman <ravelite@gmail.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 11bb5c88a1..d06807eedb 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -203,6 +203,8 @@ private slots: void highlightLongLine(); + void countTextChangedOnRemove(); + private: void createSelection(); int blockCount() const; @@ -2499,6 +2501,19 @@ void tst_QTextEdit::highlightLongLine() QVERIFY(true); } +//check for bug 15003, are there multiple textChanged() signals on remove? +void tst_QTextEdit::countTextChangedOnRemove() +{ + QTextEdit edit; + edit.insertPlainText("Hello"); + + QSignalSpy spy(&edit, SIGNAL(textChanged())); + + QKeyEvent event(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier); + QCoreApplication::instance()->notify(&edit, &event); + + QCOMPARE(spy.count(), 1); +} QTEST_MAIN(tst_QTextEdit) #include "tst_qtextedit.moc" |