1745 cursor.insertText(QLatin1String("x")); |
1747 cursor.insertText(QLatin1String("x")); |
1746 QCOMPARE(selection.position(), posBefore); |
1748 QCOMPARE(selection.position(), posBefore); |
1747 QCOMPARE(selection.anchor(), posAfter); |
1749 QCOMPARE(selection.anchor(), posAfter); |
1748 doc->undo(); |
1750 doc->undo(); |
1749 |
1751 |
1750 |
1752 } |
1751 |
1753 void tst_QTextCursor::cursorPositionWithBlockUndoAndRedo() |
1752 |
1754 { |
|
1755 cursor.insertText("AAAABBBBCCCCDDDD"); |
|
1756 cursor.beginEditBlock(); |
|
1757 cursor.setPosition(12); |
|
1758 int cursorPositionBefore = cursor.position(); |
|
1759 cursor.insertText("*"); |
|
1760 cursor.setPosition(8); |
|
1761 cursor.insertText("*"); |
|
1762 cursor.setPosition(4); |
|
1763 cursor.insertText("*"); |
|
1764 cursor.setPosition(0); |
|
1765 cursor.insertText("*"); |
|
1766 int cursorPositionAfter = cursor.position(); |
|
1767 cursor.endEditBlock(); |
|
1768 |
|
1769 QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); |
|
1770 QCOMPARE(12, cursorPositionBefore); |
|
1771 QCOMPARE(1, cursorPositionAfter); |
|
1772 |
|
1773 doc->undo(&cursor); |
|
1774 QVERIFY(doc->toPlainText() == "AAAABBBBCCCCDDDD"); |
|
1775 QCOMPARE(cursor.position(), cursorPositionBefore); |
|
1776 doc->redo(&cursor); |
|
1777 QVERIFY(doc->toPlainText() == "*AAAA*BBBB*CCCC*DDDD"); |
|
1778 QCOMPARE(cursor.position(), cursorPositionAfter); |
1753 } |
1779 } |
1754 |
1780 |
1755 QTEST_MAIN(tst_QTextCursor) |
1781 QTEST_MAIN(tst_QTextCursor) |
1756 #include "tst_qtextcursor.moc" |
1782 #include "tst_qtextcursor.moc" |