summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtextcursor
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-01-24 19:09:38 +0100
committerJiang Jiang <jiang.jiang@nokia.com>2011-01-25 13:42:50 +0100
commit34c297faca93e1286573b2a01127e4e7af00aff2 (patch)
treedc35f70a98e3e5701d33c9fb7c7304057f5d45df /tests/auto/qtextcursor
parenta0e0a9378d10db9c8ab3ba4d59f5c576ee4cbc40 (diff)
Fix cursor position adjustment when removing strings
Commit 0ba1b4d0 introduced a regression to QTextDocument: it postponed cursor position adjustment until the move operation is done, but contentsChanged will be triggered by finishEdit() in this move operation, thus cursor positions in this signal handler will be in inconsistent states (normally we should first update cursor position then trigger contentsChanged). In this case we should also postpone finishEdit() handling after cursor positions have been adjusted, then the states expose to applications will be consistent. Task-number: QTBUG-15857 Reviewed-by: Eskil
Diffstat (limited to 'tests/auto/qtextcursor')
-rw-r--r--tests/auto/qtextcursor/tst_qtextcursor.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/qtextcursor/tst_qtextcursor.cpp b/tests/auto/qtextcursor/tst_qtextcursor.cpp
index ee2baef357..4d52dd79a4 100644
--- a/tests/auto/qtextcursor/tst_qtextcursor.cpp
+++ b/tests/auto/qtextcursor/tst_qtextcursor.cpp
@@ -134,6 +134,7 @@ private slots:
void endOfLine();
void editBlocksDuringRemove();
+ void selectAllDuringRemove();
void update_data();
void update();
@@ -1388,6 +1389,17 @@ public slots:
++recordingCount;
}
+ void selectAllContents()
+ {
+ // Only test the first time
+ if (!recordingCount) {
+ recordingCount++;
+ cursor->select(QTextCursor::Document);
+ lastRecordedPosition = cursor->position();
+ lastRecordedAnchor = cursor->anchor();
+ }
+ }
+
private:
QTextCursor *cursor;
};
@@ -1411,6 +1423,22 @@ void tst_QTextCursor::editBlocksDuringRemove()
QVERIFY(doc->toPlainText().isEmpty());
}
+void tst_QTextCursor::selectAllDuringRemove()
+{
+ CursorListener listener(&cursor);
+
+ cursor.insertText("Hello World");
+ cursor.movePosition(QTextCursor::End);
+
+ connect(doc, SIGNAL(contentsChanged()), &listener, SLOT(selectAllContents()));
+ listener.recordingCount = 0;
+ QTextCursor localCursor = cursor;
+ localCursor.deletePreviousChar();
+
+ QCOMPARE(listener.lastRecordedPosition, 10);
+ QCOMPARE(listener.lastRecordedAnchor, 0);
+}
+
void tst_QTextCursor::update_data()
{
QTest::addColumn<QString>("text");