summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-07-25 16:28:07 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-26 01:35:40 +0200
commitef2384ad57c7e7ea40937cced6e6210fd371a978 (patch)
tree678c6c1234db7feda2dc2476d6ab930fb16ce5e7
parentf7acedb0887fe0980a325303cd86f54d70eabead (diff)
Update cursor position when selection is reversed.
A reversed selection will have the same resolved start and end positions but a different cursor position so testing the end points alone doesn't guarantee the selection is the same. Task-number: QTBUG-19456 Reviewed-by: Martin Jones Change-Id: I516e5a501ec878d673f21e54d688fd2d21b624ef Reviewed-on: http://codereview.qt.nokia.com/2080 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
-rw-r--r--src/gui/widgets/qlinecontrol.cpp14
-rw-r--r--tests/auto/qlineedit/tst_qlineedit.cpp12
2 files changed, 19 insertions, 7 deletions
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index 84674a51d3..550b5cf947 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -281,27 +281,27 @@ void QLineControl::setSelection(int start, int length)
}
if (length > 0) {
- if (start == m_selstart && start + length == m_selend)
- return;
+ m_selDirty |= (start != m_selstart || start + length != m_selend);
m_selstart = start;
m_selend = qMin(start + length, (int)m_text.length());
m_cursor = m_selend;
} else if (length < 0){
- if (start == m_selend && start + length == m_selstart)
- return;
+ m_selDirty |= (start != m_selend || start + length != m_selstart);
m_selstart = qMax(start + length, 0);
m_selend = start;
m_cursor = m_selstart;
} else if (m_selstart != m_selend) {
+ m_selDirty = true;
m_selstart = 0;
m_selend = 0;
m_cursor = start;
} else {
m_cursor = start;
- emitCursorPositionChanged();
- return;
}
- emit selectionChanged();
+ if (m_selDirty) {
+ m_selDirty = false;
+ emit selectionChanged();
+ }
emitCursorPositionChanged();
}
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp
index d178e26476..72b402f69d 100644
--- a/tests/auto/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/qlineedit/tst_qlineedit.cpp
@@ -289,6 +289,8 @@ private slots:
void bidiLogicalMovement_data();
void bidiLogicalMovement();
+ void selectAndCursorPosition();
+
protected slots:
void editingFinished();
@@ -3871,5 +3873,15 @@ void tst_QLineEdit::bidiLogicalMovement()
} while (moved && i >= 0);
}
+void tst_QLineEdit::selectAndCursorPosition()
+{
+ testWidget->setText("This is a long piece of text");
+
+ testWidget->setSelection(0, 5);
+ QCOMPARE(testWidget->cursorPosition(), 5);
+ testWidget->setSelection(5, -5);
+ QCOMPARE(testWidget->cursorPosition(), 0);
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"