QTextLayout: Fix visual cursor movement in some cases
To guarantee proper positioning at the end of the last line in a bidirectional text we have to insert the eol position into the insertion points vector, accordingly to the visual ordering. Detection of the last *logical* item in a *visual* line is unrelaed to the text direction, it is simply `iterator.item == iterator.lastItem`. [ChangeLog][QtGui][QTextLayout] Fixed visual cursor movement in bidirectional text. Task-number: QTBUG-18060 (partially related) Change-Id: I53b6ab889ef580ab0560b620b808b1e09efc0fbd Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Ahmed Saidi <justroftest@gmail.com>
This commit is contained in:
parent
d828672945
commit
0b5911f376
@ -3181,23 +3181,19 @@ int QTextEngine::lineNumberForTextPosition(int pos)
|
||||
void QTextEngine::insertionPointsForLine(int lineNum, QVector<int> &insertionPoints)
|
||||
{
|
||||
QTextLineItemIterator iterator(this, lineNum);
|
||||
bool rtl = isRightToLeft();
|
||||
bool lastLine = lineNum >= lines.size() - 1;
|
||||
|
||||
while (!iterator.atEnd()) {
|
||||
iterator.next();
|
||||
const QScriptItem *si = &layoutData->items[iterator.item];
|
||||
if (si->analysis.bidiLevel % 2) {
|
||||
int i = iterator.itemEnd - 1, min = iterator.itemStart;
|
||||
if (lastLine && (rtl ? iterator.atBeginning() : iterator.atEnd()))
|
||||
i++;
|
||||
for (; i >= min; i--)
|
||||
const QScriptItem &si = iterator.next();
|
||||
|
||||
int end = iterator.itemEnd;
|
||||
if (lastLine && iterator.item == iterator.lastItem)
|
||||
++end; // the last item in the last line -> insert eol position
|
||||
if (si.analysis.bidiLevel % 2) {
|
||||
for (int i = end - 1; i >= iterator.itemStart; --i)
|
||||
insertionPoints.push_back(i);
|
||||
} else {
|
||||
int i = iterator.itemStart, max = iterator.itemEnd;
|
||||
if (lastLine && (rtl ? iterator.atBeginning() : iterator.atEnd()))
|
||||
max++;
|
||||
for (; i < max; i++)
|
||||
for (int i = iterator.itemStart; i < end; ++i)
|
||||
insertionPoints.push_back(i);
|
||||
}
|
||||
}
|
||||
|
@ -3903,7 +3903,7 @@ void tst_QLineEdit::bidiVisualMovement()
|
||||
|
||||
do {
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == positionList[i]);
|
||||
QCOMPARE(oldPos, positionList[i]);
|
||||
if (basicDir == QChar::DirL) {
|
||||
QTest::keyClick(&le, Qt::Key_Right);
|
||||
} else
|
||||
@ -3913,12 +3913,12 @@ void tst_QLineEdit::bidiVisualMovement()
|
||||
i++;
|
||||
} while (moved);
|
||||
|
||||
QVERIFY(i == positionList.size());
|
||||
QCOMPARE(i, positionList.size());
|
||||
|
||||
do {
|
||||
i--;
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == positionList[i]);
|
||||
QCOMPARE(oldPos, positionList[i]);
|
||||
if (basicDir == QChar::DirL) {
|
||||
QTest::keyClick(&le, Qt::Key_Left);
|
||||
} else
|
||||
@ -3939,6 +3939,7 @@ void tst_QLineEdit::bidiLogicalMovement()
|
||||
{
|
||||
QFETCH(QString, logical);
|
||||
QFETCH(int, basicDir);
|
||||
QFETCH(IntList, positionList);
|
||||
|
||||
QLineEdit le;
|
||||
le.setText(logical);
|
||||
@ -3951,7 +3952,7 @@ void tst_QLineEdit::bidiLogicalMovement()
|
||||
|
||||
do {
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == i);
|
||||
QCOMPARE(oldPos, i);
|
||||
if (basicDir == QChar::DirL) {
|
||||
QTest::keyClick(&le, Qt::Key_Right);
|
||||
} else
|
||||
@ -3961,10 +3962,12 @@ void tst_QLineEdit::bidiLogicalMovement()
|
||||
i++;
|
||||
} while (moved);
|
||||
|
||||
QCOMPARE(i, positionList.size());
|
||||
|
||||
do {
|
||||
i--;
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == i);
|
||||
QCOMPARE(oldPos, i);
|
||||
if (basicDir == QChar::DirL) {
|
||||
QTest::keyClick(&le, Qt::Key_Left);
|
||||
} else
|
||||
|
@ -2304,7 +2304,7 @@ void tst_QTextEdit::bidiVisualMovement()
|
||||
|
||||
do {
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == positionList[i]);
|
||||
QCOMPARE(oldPos, positionList[i]);
|
||||
if (basicDir == QChar::DirL) {
|
||||
ed->moveCursor(QTextCursor::Right);
|
||||
} else
|
||||
@ -2316,12 +2316,12 @@ void tst_QTextEdit::bidiVisualMovement()
|
||||
i++;
|
||||
} while (moved);
|
||||
|
||||
QVERIFY(i == positionList.size());
|
||||
QCOMPARE(i, positionList.size());
|
||||
|
||||
do {
|
||||
i--;
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == positionList[i]);
|
||||
QCOMPARE(oldPos, positionList[i]);
|
||||
if (basicDir == QChar::DirL) {
|
||||
ed->moveCursor(QTextCursor::Left);
|
||||
} else
|
||||
@ -2342,6 +2342,7 @@ void tst_QTextEdit::bidiLogicalMovement()
|
||||
{
|
||||
QFETCH(QString, logical);
|
||||
QFETCH(int, basicDir);
|
||||
QFETCH(QList<int>, positionList);
|
||||
|
||||
ed->setText(logical);
|
||||
|
||||
@ -2358,7 +2359,7 @@ void tst_QTextEdit::bidiLogicalMovement()
|
||||
|
||||
do {
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == i);
|
||||
QCOMPARE(oldPos, i);
|
||||
if (basicDir == QChar::DirL) {
|
||||
ed->moveCursor(QTextCursor::Right);
|
||||
} else
|
||||
@ -2370,10 +2371,12 @@ void tst_QTextEdit::bidiLogicalMovement()
|
||||
i++;
|
||||
} while (moved);
|
||||
|
||||
QCOMPARE(i, positionList.size());
|
||||
|
||||
do {
|
||||
i--;
|
||||
oldPos = newPos;
|
||||
QVERIFY(oldPos == i);
|
||||
QCOMPARE(oldPos, i);
|
||||
if (basicDir == QChar::DirL) {
|
||||
ed->moveCursor(QTextCursor::Left);
|
||||
} else
|
||||
|
Loading…
Reference in New Issue
Block a user