summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtextcursor
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qtextcursor')
-rw-r--r--tests/auto/qtextcursor/tst_qtextcursor.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/qtextcursor/tst_qtextcursor.cpp b/tests/auto/qtextcursor/tst_qtextcursor.cpp
index 88ecc73..d910c8d 100644
--- a/tests/auto/qtextcursor/tst_qtextcursor.cpp
+++ b/tests/auto/qtextcursor/tst_qtextcursor.cpp
@@ -147,6 +147,8 @@ private slots:
void task244408_wordUnderCursor_data();
void task244408_wordUnderCursor();
+ void adjustCursorsOnInsert();
+
private:
int blockCount();
@@ -1658,5 +1660,97 @@ void tst_QTextCursor::task244408_wordUnderCursor()
QCOMPARE(cursor.selectedText(), expected);
}
+void tst_QTextCursor::adjustCursorsOnInsert()
+{
+ cursor.insertText("Some text before ");
+ int posBefore = cursor.position();
+ cursor.insertText("selected text");
+ int posAfter = cursor.position();
+ cursor.insertText(" some text afterwards");
+
+ QTextCursor selection = cursor;
+ selection.setPosition(posBefore);
+ selection.setPosition(posAfter, QTextCursor::KeepAnchor);
+
+ cursor.setPosition(posBefore-1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore+1);
+ QCOMPARE(selection.position(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posBefore);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore+1);
+ QCOMPARE(selection.position(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posBefore+1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore);
+ QCOMPARE(selection.position(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posAfter-1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore);
+ QCOMPARE(selection.position(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posAfter);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore);
+ QCOMPARE(selection.position(), posAfter);
+ doc->undo();
+
+ cursor.setPosition(posAfter+1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.anchor(), posBefore);
+ QCOMPARE(selection.position(), posAfter);
+ doc->undo();
+
+ selection.setPosition(posAfter);
+ selection.setPosition(posBefore, QTextCursor::KeepAnchor);
+
+ cursor.setPosition(posBefore-1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore+1);
+ QCOMPARE(selection.anchor(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posBefore);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore+1);
+ QCOMPARE(selection.anchor(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posBefore+1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore);
+ QCOMPARE(selection.anchor(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posAfter-1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore);
+ QCOMPARE(selection.anchor(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posAfter);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore);
+ QCOMPARE(selection.anchor(), posAfter+1);
+ doc->undo();
+
+ cursor.setPosition(posAfter+1);
+ cursor.insertText(QLatin1String("x"));
+ QCOMPARE(selection.position(), posBefore);
+ QCOMPARE(selection.anchor(), posAfter);
+ doc->undo();
+
+
+
+
+}
+
QTEST_MAIN(tst_QTextCursor)
#include "tst_qtextcursor.moc"