From 159ccaa57f6f653c36af47910b98e106be5112bc Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Mon, 25 Mar 2013 16:52:45 +0100 Subject: [PATCH] QQuickTextEdit: make the update logic work with multiple text frames 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 Reviewed-by: Jens Bache-Wiig Reviewed-by: Alan Alpert --- src/quick/items/qquicktextedit.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index dde3587..2facb98 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -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()) { -- 2.7.4