diff options
author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2013-04-23 10:04:28 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-23 11:26:14 +0200 |
commit | 5f7ba49e2501286670e19ee8ba7d48b169fa3330 (patch) | |
tree | f15759630065bae0370a8980abb373beb486bb3e | |
parent | e865df80a907ceb3354a3369f9467022f451d692 (diff) |
TextInput: Fix cursor navigation with mask
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>
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 0d0d0a17e0..65a0d6215a 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -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) { diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index d1ed6dd05a..4ffbe9ccd5 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -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() |