Commit 0e1baa28 authored by Andrew den Exter's avatar Andrew den Exter Committed by Qt by Nokia

Content size should not include trailing spaces.

Excluding trailing spaces from the content size means the cursor
position also needs to considered in determining the width used
by the text as unwrapped white space can push the cursor over
the width of the item.

Also corrects an auto scroll issue with right to left text
identified in extending the tests.

Task-number: QTBUG-24630

Change-Id: Iaab9eac03824b22f507154fa1d6e55376bd075a0
Reviewed-by: 's avatarYann Bodson <yann.bodson@nokia.com>
parent 122e8df4
......@@ -1614,14 +1614,19 @@ void QQuickTextInputPrivate::updateHorizontalScroll()
QTextLine currentLine = m_textLayout.lineForTextPosition(m_cursor + m_preeditCursor);
const int preeditLength = m_textLayout.preeditAreaText().length();
const qreal width = qMax<qreal>(0, q->width());
qreal widthUsed = currentLine.isValid() ? currentLine.naturalTextWidth() : 0;
qreal cix = 0;
qreal widthUsed = 0;
if (currentLine.isValid()) {
cix = currentLine.cursorToX(m_cursor + preeditLength);
const qreal cursorWidth = cix >= 0 ? cix : width - cix;
widthUsed = qMax(currentLine.naturalTextWidth(), cursorWidth);
}
int previousScroll = hscroll;
if (!autoScroll || widthUsed <= width || m_echoMode == QQuickTextInput::NoEcho) {
hscroll = 0;
} else {
Q_ASSERT(currentLine.isValid());
qreal cix = currentLine.cursorToX(m_cursor + preeditLength);
if (cix - hscroll >= width) {
// text doesn't fit, cursor is to the right of br (scroll right)
hscroll = cix - width;
......@@ -1632,6 +1637,10 @@ void QQuickTextInputPrivate::updateHorizontalScroll()
// text doesn't fit, text document is to the left of br; align
// right
hscroll = widthUsed - width;
} else if (width - hscroll > widthUsed) {
// text doesn't fit, text document is to the right of br; align
// left
hscroll = width - widthUsed;
}
if (preeditLength > 0) {
// check to ensure long pre-edit text doesn't push the cursor
......@@ -2699,7 +2708,6 @@ void QQuickTextInputPrivate::updateLayout()
QTextOption option = m_textLayout.textOption();
option.setTextDirection(layoutDirection());
option.setFlags(QTextOption::IncludeTrailingSpaces);
option.setWrapMode(QTextOption::WrapMode(wrapMode));
option.setAlignment(Qt::Alignment(q->effectiveHAlign()));
m_textLayout.setTextOption(option);
......@@ -2710,7 +2718,6 @@ void QQuickTextInputPrivate::updateLayout()
QTextLine line = m_textLayout.createLine();
qreal lineWidth = q->widthValid() ? q->width() : INT_MAX;
qreal height = 0;
QTextLine firstLine = line;
do {
line.setLineWidth(lineWidth);
line.setPosition(QPointF(line.position().x(), height));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment