diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-06 16:05:33 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-24 07:53:05 +0200 |
commit | 919b60b4fcc72fdcd5dc0e80e642f922da17cd96 (patch) | |
tree | a76188afdfa613a1199e8650354578f1027714e6 /tests/auto/quick | |
parent | dbe4d2010816f1f22f48f3f5bce0d15d3ad7a7e2 (diff) |
Fix restoration of cursor position and selection after undo/redo.
If a text selection was deleted, the selection should be restored by an
undo, but not if the selection was part of an atomic operation like
the DeleteStartOfWord key sequence.
Change-Id: Ia37f29c78f6367c60377c539c4e394e014485a49
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 146 |
1 files changed, 142 insertions, 4 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index a4d1920350..7cc9ddb8f2 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -192,6 +192,8 @@ private slots: void undo_keypressevents_data(); void undo_keypressevents(); + void backspaceSurrogatePairs(); + void QTBUG_19956(); void QTBUG_19956_data(); void QTBUG_19956_regexp(); @@ -236,8 +238,8 @@ Q_DECLARE_METATYPE(KeyList) void tst_qquicktextinput::simulateKeys(QWindow *window, const QList<Key> &keys) { for (int i = 0; i < keys.count(); ++i) { - const int key = keys.at(i).first; - const int modifiers = key & Qt::KeyboardModifierMask; + const int key = keys.at(i).first & ~Qt::KeyboardModifierMask; + const int modifiers = keys.at(i).first & Qt::KeyboardModifierMask; const QString text = !keys.at(i).second.isNull() ? QString(keys.at(i).second) : QString(); QKeyEvent press(QEvent::KeyPress, Qt::Key(key), Qt::KeyboardModifiers(modifiers), text); @@ -5138,7 +5140,7 @@ void tst_qquicktextinput::undo_keypressevents_data() << QKeySequence::MoveToStartOfLine // selecting 'AB' << (Qt::Key_Right | Qt::ShiftModifier) << (Qt::Key_Right | Qt::ShiftModifier) - << Qt::Key_Delete + << Qt::Key_Backspace << QKeySequence::Undo << Qt::Key_Right << (Qt::Key_Right | Qt::ShiftModifier) << (Qt::Key_Right | Qt::ShiftModifier) @@ -5213,7 +5215,6 @@ void tst_qquicktextinput::undo_keypressevents_data() << "ABC"; expectedString << "ABC"; - // for versions previous to 3.2 we overwrite needed two undo operations expectedString << "123"; QTest::newRow("Inserts,moving,selection and overwriting") << keys << expectedString; @@ -5230,6 +5231,106 @@ void tst_qquicktextinput::undo_keypressevents_data() expectedString << QString(); QTest::newRow("Insert,undo,redo") << keys << expectedString; + } { + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << (Qt::Key_Backspace | Qt::ControlModifier) + << QKeySequence::Undo + << QKeySequence::Redo + << "hello"; + + expectedString + << "hello hello" + << "hello " + << "hello world" + << QString(); + + QTest::newRow("Insert,delete previous word,undo,redo,insert") << keys << expectedString; + } { + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << QKeySequence::SelectPreviousWord + << (Qt::Key_Backspace) + << QKeySequence::Undo + << "hello"; + + expectedString + << "hello hello" + << "hello world" + << QString(); + + QTest::newRow("Insert,select previous word,remove,undo,insert") << keys << expectedString; + } { + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << QKeySequence::DeleteStartOfWord + << QKeySequence::Undo + << "hello"; + + expectedString + << "hello worldhello" + << "hello world" + << QString(); + + QTest::newRow("Insert,delete previous word,undo,insert") << keys << expectedString; + } { + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << QKeySequence::MoveToPreviousWord + << QKeySequence::DeleteEndOfWord + << QKeySequence::Undo + << "hello"; + + expectedString + << "hello helloworld" + << "hello world" + << QString(); + + QTest::newRow("Insert,move,delete next word,undo,insert") << keys << expectedString; + } + if (!QKeySequence(QKeySequence::DeleteEndOfLine).isEmpty()) { // X11 only. + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << QKeySequence::MoveToStartOfLine + << Qt::Key_Right + << QKeySequence::DeleteEndOfLine + << QKeySequence::Undo + << "hello"; + + expectedString + << "hhelloello world" + << "hello world" + << QString(); + + QTest::newRow("Insert,move,delete end of line,undo,insert") << keys << expectedString; + } { + KeyList keys; + QStringList expectedString; + + keys << "hello world" + << QKeySequence::MoveToPreviousWord + << (Qt::Key_Left | Qt::ShiftModifier) + << (Qt::Key_Left | Qt::ShiftModifier) + << QKeySequence::DeleteEndOfWord + << QKeySequence::Undo + << "hello"; + + expectedString + << "hellhelloworld" + << "hello world" + << QString(); + + QTest::newRow("Insert,move,select,delete next word,undo,insert") << keys << expectedString; } } @@ -5260,6 +5361,43 @@ void tst_qquicktextinput::undo_keypressevents() QVERIFY(textInput->text().isEmpty()); } +void tst_qquicktextinput::backspaceSurrogatePairs() +{ + // Test backspace, and delete remove both characters in a surrogate pair. + static const quint16 textData[] = { 0xd800, 0xdf00, 0xd800, 0xdf01, 0xd800, 0xdf02, 0xd800, 0xdf03, 0xd800, 0xdf04 }; + const QString text = QString::fromUtf16(textData, lengthOf(textData)); + + QString componentStr = "import QtQuick 2.0\nTextInput { focus: true }"; + QQmlComponent textInputComponent(&engine); + textInputComponent.setData(componentStr.toLatin1(), QUrl()); + QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create()); + QVERIFY(textInput != 0); + textInput->setText(text); + textInput->setCursorPosition(text.length()); + + QQuickWindow window; + textInput->setParentItem(window.contentItem()); + window.show(); + window.requestActivateWindow(); + QTest::qWaitForWindowShown(&window); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + + for (int i = text.length(); i >= 0; i -= 2) { + QCOMPARE(textInput->text(), text.mid(0, i)); + QTest::keyClick(&window, Qt::Key_Backspace, Qt::NoModifier); + } + QCOMPARE(textInput->text(), QString()); + + textInput->setText(text); + textInput->setCursorPosition(0); + + for (int i = 0; i < text.length(); i += 2) { + QCOMPARE(textInput->text(), text.mid(i)); + QTest::keyClick(&window, Qt::Key_Delete, Qt::NoModifier); + } + QCOMPARE(textInput->text(), QString()); +} + void tst_qquicktextinput::QTBUG_19956() { QFETCH(QString, url); |