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>
This commit is contained in:
parent
f7acedb088
commit
ef2384ad57
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user