aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-03-12 13:39:23 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-20 06:49:30 +0100
commitb93b4a74825ce9adacdbd1d759d5ed696c35b36a (patch)
tree702644d8f2ba187ce86f6c9195f3e52b220af092
parent0f1be99881883b28a80f0e5f276ea3bb544a9611 (diff)
Make TextEdit word selection behaviour consistent.
Word selection initiated by a double click in QTextEdit only selects a word if the drag point is closer to the end than the start (assuming ltr selection) which can make it difficult to select small words with touch input, as such the SelectWords mouseSelectionMode of TextEdit selected a word if the drag point intersected any part of the word. Since we no longer have to retain compability for QTextEdit we can settle on a single behaviour for word selection. Change-Id: Iaabb7938a2b61b84a290a9ee41e407c83144b96f Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
-rw-r--r--src/quick/items/qquicktextcontrol.cpp27
-rw-r--r--tests/auto/quick/qquicktextedit/data/mouseselection_true.qml2
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp45
3 files changed, 37 insertions, 37 deletions
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp
index 53d736eab1..1846d03b9b 100644
--- a/src/quick/items/qquicktextcontrol.cpp
+++ b/src/quick/items/qquicktextcontrol.cpp
@@ -531,29 +531,12 @@ void QQuickTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition,
if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX))
return;
- if (wordSelectionEnabled) {
- if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
- cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
- setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
- } else {
- cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
- setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
- }
+ if (suggestedNewPosition < selectedWordOnDoubleClick.position()) {
+ cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
+ setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
} else {
- // keep the already selected word even when moving to the left
- // (#39164)
- if (suggestedNewPosition < selectedWordOnDoubleClick.position())
- cursor.setPosition(selectedWordOnDoubleClick.selectionEnd());
- else
- cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
-
- const qreal differenceToStart = mouseXPosition - wordStartX;
- const qreal differenceToEnd = wordEndX - mouseXPosition;
-
- if (differenceToStart < differenceToEnd)
- setCursorPosition(wordStartPos, QTextCursor::KeepAnchor);
- else
- setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
+ cursor.setPosition(selectedWordOnDoubleClick.selectionStart());
+ setCursorPosition(wordEndPos, QTextCursor::KeepAnchor);
}
if (interactionFlags & Qt::TextSelectableByMouse) {
diff --git a/tests/auto/quick/qquicktextedit/data/mouseselection_true.qml b/tests/auto/quick/qquicktextedit/data/mouseselection_true.qml
index 7c7cb0b6fc..b7a15962f4 100644
--- a/tests/auto/quick/qquicktextedit/data/mouseselection_true.qml
+++ b/tests/auto/quick/qquicktextedit/data/mouseselection_true.qml
@@ -2,6 +2,6 @@ import QtQuick 2.0
TextEdit {
focus: true
- text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
selectByMouse: true
}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 8d346891dc..7b3c8468b9 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -1563,21 +1563,32 @@ void tst_qquicktextedit::mouseSelection_data()
QTest::addColumn<int>("from");
QTest::addColumn<int>("to");
QTest::addColumn<QString>("selectedText");
+ QTest::addColumn<bool>("doubleClick");
// import installed
- QTest::newRow("on") << testFile("mouseselection_true.qml") << 4 << 9 << "45678";
- QTest::newRow("off") << testFile("mouseselection_false.qml") << 4 << 9 << QString();
- QTest::newRow("default") << testFile("mouseselection_default.qml") << 4 << 9 << QString();
- QTest::newRow("off word selection") << testFile("mouseselection_false_words.qml") << 4 << 9 << QString();
- QTest::newRow("on word selection (4,9)") << testFile("mouseselection_true_words.qml") << 4 << 9 << "0123456789";
- QTest::newRow("on word selection (2,13)") << testFile("mouseselection_true_words.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (2,30)") << testFile("mouseselection_true_words.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (9,13)") << testFile("mouseselection_true_words.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (9,30)") << testFile("mouseselection_true_words.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (13,2)") << testFile("mouseselection_true_words.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (20,2)") << testFile("mouseselection_true_words.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (12,9)") << testFile("mouseselection_true_words.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- QTest::newRow("on word selection (30,9)") << testFile("mouseselection_true_words.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ QTest::newRow("on") << testFile("mouseselection_true.qml") << 4 << 9 << "45678" << false;
+ QTest::newRow("off") << testFile("mouseselection_false.qml") << 4 << 9 << QString() << false;
+ QTest::newRow("default") << testFile("mouseselection_default.qml") << 4 << 9 << QString() << false;
+ QTest::newRow("off word selection") << testFile("mouseselection_false_words.qml") << 4 << 9 << QString() << false;
+ QTest::newRow("on word selection (4,9)") << testFile("mouseselection_true_words.qml") << 4 << 9 << "0123456789" << false;
+ QTest::newRow("on word selection (2,13)") << testFile("mouseselection_true_words.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (2,30)") << testFile("mouseselection_true_words.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (9,13)") << testFile("mouseselection_true_words.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (9,30)") << testFile("mouseselection_true_words.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (13,2)") << testFile("mouseselection_true_words.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (20,2)") << testFile("mouseselection_true_words.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (12,9)") << testFile("mouseselection_true_words.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+ QTest::newRow("on word selection (30,9)") << testFile("mouseselection_true_words.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << false;
+
+ QTest::newRow("off double click (4,9)") << testFile("mouseselection_true.qml") << 4 << 9 << "0123456789" << true;
+ QTest::newRow("off double click (2,13)") << testFile("mouseselection_true.qml") << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (2,30)") << testFile("mouseselection_true.qml") << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (9,13)") << testFile("mouseselection_true.qml") << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (9,30)") << testFile("mouseselection_true.qml") << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (13,2)") << testFile("mouseselection_true.qml") << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (20,2)") << testFile("mouseselection_true.qml") << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (12,9)") << testFile("mouseselection_true.qml") << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
+ QTest::newRow("off double click (30,9)") << testFile("mouseselection_true.qml") << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" << true;
}
void tst_qquicktextedit::mouseSelection()
@@ -1586,6 +1597,7 @@ void tst_qquicktextedit::mouseSelection()
QFETCH(int, from);
QFETCH(int, to);
QFETCH(QString, selectedText);
+ QFETCH(bool, doubleClick);
QQuickView canvas(QUrl::fromLocalFile(qmlfile));
@@ -1601,6 +1613,8 @@ void tst_qquicktextedit::mouseSelection()
// press-and-drag-and-release from x1 to x2
QPoint p1 = textEditObject->positionToRectangle(from).center().toPoint();
QPoint p2 = textEditObject->positionToRectangle(to).center().toPoint();
+ if (doubleClick)
+ QTest::mouseClick(&canvas, Qt::LeftButton, 0, p1);
QTest::mousePress(&canvas, Qt::LeftButton, 0, p1);
QTest::mouseMove(&canvas, p2);
QTest::mouseRelease(&canvas, Qt::LeftButton, 0, p2);
@@ -1609,7 +1623,10 @@ void tst_qquicktextedit::mouseSelection()
// Clicking and shift to clicking between the same points should select the same text.
textEditObject->setCursorPosition(0);
- QTest::mouseClick(&canvas, Qt::LeftButton, Qt::NoModifier, p1);
+ if (doubleClick)
+ QTest::mouseDClick(&canvas, Qt::LeftButton, 0, p1);
+ else
+ QTest::mouseClick(&canvas, Qt::LeftButton, Qt::NoModifier, p1);
QTest::mouseClick(&canvas, Qt::LeftButton, Qt::ShiftModifier, p2);
QTest::qWait(50);
QTRY_COMPARE(textEditObject->selectedText(), selectedText);