Fix visibility of trailing preedit text.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 3 Apr 2012 06:10:33 +0000 (16:10 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 3 Apr 2012 07:22:14 +0000 (09:22 +0200)
The block iterator doesn't take into account pre-edit text so we need
to explicitly add pre-edit if it is positioned after the last fragment
in a block.

Change-Id: I1d26ee3ff86ea27674fc4f165b23ac5692a9ec17
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
src/quick/items/qquicktextnode.cpp

index 5be4963..89c0aec 100644 (file)
@@ -1219,12 +1219,6 @@ void QQuickTextNode::addTextDocument(const QPointF &position, QTextDocument *tex
 
                 int textPos = block.position();
                 QTextBlock::iterator blockIterator = block.begin();
-                if (blockIterator.atEnd() && preeditLength) {
-                    engine.setPosition(blockPosition);
-                    textPos = engine.addText(block, block.charFormat(), textColor, colorChanges,
-                                             textPos, textPos + preeditLength,
-                                             selectionStart, selectionEnd);
-                }
 
                 while (!blockIterator.atEnd()) {
                     QTextFragment fragment = blockIterator.fragment();
@@ -1275,6 +1269,19 @@ void QQuickTextNode::addTextDocument(const QPointF &position, QTextDocument *tex
                     ++blockIterator;
                 }
 
+                if (preeditLength >= 0 && textPos <= block.position() + preeditPosition) {
+                    engine.setPosition(blockPosition);
+                    textPos = block.position() + preeditPosition;
+                    QTextLine line = block.layout()->lineForTextPosition(textPos);
+                    if (!engine.currentLine().isValid()
+                            || line.lineNumber() != engine.currentLine().lineNumber()) {
+                        engine.setCurrentLine(line);
+                    }
+                    textPos = engine.addText(block, block.charFormat(), textColor, colorChanges,
+                                             textPos, textPos + preeditLength,
+                                             selectionStart, selectionEnd);
+                }
+
                 engine.setCurrentLine(QTextLine()); // Reset current line because the text layout changed
                 ++it;
             }