TextInput: Fix cursor navigation with mask
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Tue, 23 Apr 2013 08:04:28 +0000 (10:04 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 23 Apr 2013 09:26:14 +0000 (11:26 +0200)
text().length() was used to check if a cursor movement
to the right was valid. The problem is that with a mask and
not text set yet (inputMask: "#0:00;*") pressing the right
arrow would not move the cursor.
The input and other functions use the actual d->m_text
since that includes the mask length.

Task-number: QTBUG-30740

Change-Id: Ic225778e5a49d80b754b63d0eb4a438eaa9818e2
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
src/quick/items/qquicktextinput.cpp
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index 0d0d0a1..65a0d62 100644 (file)
@@ -1470,7 +1470,7 @@ void QQuickTextInput::keyPressEvent(QKeyEvent* ev)
         int cursorPosition = d->m_cursor;
         if (cursorPosition == 0)
             ignore = ev->key() == (d->layoutDirection() == Qt::LeftToRight ? Qt::Key_Left : Qt::Key_Right);
-        if (!ignore && cursorPosition == text().length())
+        if (!ignore && cursorPosition == d->m_text.length())
             ignore = ev->key() == (d->layoutDirection() == Qt::LeftToRight ? Qt::Key_Right : Qt::Key_Left);
     }
     if (ignore) {
index d1ed6dd..4ffbe9c 100644 (file)
@@ -6123,6 +6123,12 @@ void tst_qquicktextinput::keypress_inputMask_data()
         keys << Qt::Key_Home << "12ab";
         QTest::newRow("uppercase") << QString("9999 >AA;_") << keys << QString("12 AB") << QString("12__ AB");
     }
+    {
+        KeyList keys;
+        // inserting '12ab'
+        keys << Qt::Key_Right << Qt::Key_Right << "1";
+        QTest::newRow("Move in mask") << QString("#0:00;*") << keys << QString(":1") << QString("**:1*");
+    }
 }
 
 void tst_qquicktextinput::keypress_inputMask()