QQuickTextEdit: make the update logic work with multiple text frames
authorPierre Rossi <pierre.rossi@digia.com>
Mon, 25 Mar 2013 15:52:45 +0000 (16:52 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 24 Apr 2013 12:12:01 +0000 (14:12 +0200)
We can't assume that the text nodes are added in order since we're
iterating over all the blocks of a text frame before processing its child
text frames. The only way for all this not to collapse is to sort the text
nodes once we're done each time we're replacing/adding new ones.

Task-number: QTBUG-30349
Change-Id: Ia5d804f7f196b2348fd68fdd62a6585c189baaa4
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
src/quick/items/qquicktextedit.cpp

index dde3587..2facb98 100644 (file)
@@ -1805,14 +1805,13 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
                         transformMatrix.translate(nodeOffset.x(), nodeOffset.y());
                         node->setMatrix(transformMatrix);
                     }
-
                     node->m_engine->addTextBlock(d->document, block, basePosition - nodeOffset, d->color, QColor(), selectionStart(), selectionEnd() - 1);
                     sizeCounter += block.length();
 
                     if ((it.atEnd() && frames.isEmpty()) || (firstCleanNode && block.next().position() >= firstCleanNode->startPos())) // last node that needed replacing or last block of the last frame
                         break;
 
-                    if (sizeCounter > nodeBreakingSize) {
+                    if (sizeCounter > nodeBreakingSize || it.atEnd()) { // text block grouping across text frames might not be a good idea, split it.
                         sizeCounter = 0;
                         node->m_engine->addToSceneGraph(node, QQuickText::Normal, QColor());
                         nodeIterator = d->textNodeMap.insert(nodeIterator, new TextNode(prevBlockStart, node));
@@ -1848,6 +1847,10 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
             }
 
         }
+
+        // Since we iterate over blocks from different text frames that are potentially not sorted
+        // we need to ensure that our list of nodes is sorted again:
+        std::sort(d->textNodeMap.begin(), d->textNodeMap.end(), &comesBefore);
     }
 
     if (d->cursorComponent == 0 && !isReadOnly()) {