diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-10-17 13:45:25 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-10-23 08:59:19 +0000 |
commit | b6d6d15ab80d3ab4b078535b597d854a707160c5 (patch) | |
tree | 39ac9eb212a60ad5837d00feec66d4da11eeb754 | |
parent | d3314c7412cc43702a110e0561c546be3d952af6 (diff) |
TextEdit: deal with scrolling backwards in plain text
When the user scrolls backwards, we have a backwards iteration loop to
find the block that is at or above the top of the viewport. But if the
user tried to jump-scroll by some distance, boundingRect() and
nodeOffset were staying constant, so the iteration tended to go all the
way back to the first block. We need to update nodeOffset at each step.
Amends cd083920b3b4f3a1ed7f2297058cf0d110d7cf10
Fixes: QTBUG-104526
Change-Id: I590f59baf7137f78c4c294aa2bfbb040c80d4874
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit bc578350838e56a82e6f0c0e4d1492e4a0e8be81)
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index c035486eda..33d47757fd 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -2246,13 +2246,16 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData * if (coveredRegion.top() > viewport.top() + 1) { qCDebug(lcVP) << "checking backwards from block" << block.blockNumber() << "@" << nodeOffset.y() << coveredRegion; while (it != textFrame->begin() && it.currentBlock().layout() && - it.currentBlock().layout()->boundingRect().top() + nodeOffset.y() > viewport.top()) + it.currentBlock().layout()->boundingRect().top() + nodeOffset.y() > viewport.top()) { + nodeOffset = d->document->documentLayout()->blockBoundingRect(it.currentBlock()).topLeft(); --it; + } if (!it.currentBlock().layout()) ++it; if (Q_LIKELY(it.currentBlock().layout())) { block = it.currentBlock(); coveredRegion = block.layout()->boundingRect().adjusted(nodeOffset.x(), nodeOffset.y(), nodeOffset.x(), nodeOffset.y()); + firstDirtyPos = it.currentBlock().position(); } else { qCWarning(lcVP) << "failed to find a text block with layout during back-scrolling"; } @@ -2303,7 +2306,7 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData * nodeStart = block.next().position(); } ++it; - } + } // loop over blocks in frame } if (Q_LIKELY(node && !node->parent())) d->addCurrentTextNodeToRoot(&engine, rootNode, node, nodeIterator, nodeStart); |