summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtextcursor
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2009-09-23 13:28:24 (GMT)
committermae <qt-info@nokia.com>2009-09-23 13:40:56 (GMT)
commitbfdee5f1658b1bac4a0d1b93c5a45dbc6709f9e3 (patch)
treef932576dd3d0fbbceff65a8648e5bb764f62d82c /tests/auto/qtextcursor
parente97b99f249ed65c6cedfc23f751a9834641271cb (diff)
downloadQt-bfdee5f1658b1bac4a0d1b93c5a45dbc6709f9e3.zip
Qt-bfdee5f1658b1bac4a0d1b93c5a45dbc6709f9e3.tar.gz
Qt-bfdee5f1658b1bac4a0d1b93c5a45dbc6709f9e3.tar.bz2
QTextCursor selection extension when inserting characters
The change makes QTextCursor not extend the selection when inserting characters at the end of the selection, provided that the cursor position is at the end. Reviewed-by: Simon Hausmann Reviewed-by: Roberto Raggi
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"