aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-02-03 13:39:42 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-02-17 08:56:50 +0000
commitece8d59598fa1f8783d054ce2218b2b462cb93ee (patch)
treebbceb7d1f19ce4993fc3eeebd1dc9ee298f4c5ce
parent427ca15418c05e628bae3451c263be198e721ba9 (diff)
Fix off-by-one when checking overlaps in selection ranges
This was found while researching QTBUG-49596. The selection ranges in the QGlyphRun are inclusive, so the length needs to be end - start + 1. For a node of 1 glyph with either preceding or succeeding node, we would detect an overlap always, since the initial rangeLength would be 0. This is reproduced by the textinput_selected_fallback_font.qml test, but the bug was hidden by a different bug in QTextLayout. Change-Id: I65d70b1223eebeb5cfbb277fade7f4753465364f Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index a65b98acd1..18cb1d0083 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -822,14 +822,15 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode,
for (int i = 0; i < node->ranges.size(); ++i) {
const QPair<int, int> &range = node->ranges.at(i);
- int rangeLength = range.second - range.first;
+ int rangeLength = range.second - range.first + 1;
if (previousNode != 0) {
for (int j = 0; j < previousNode->ranges.size(); ++j) {
const QPair<int, int> &otherRange = previousNode->ranges.at(j);
+
if (range.first < otherRange.second && range.second > otherRange.first) {
int start = qMax(range.first, otherRange.first);
int end = qMin(range.second, otherRange.second);
- rangeLength -= end - start;
+ rangeLength -= end - start + 1;
if (rangeLength == 0)
break;
}
@@ -843,7 +844,7 @@ void QQuickTextNodeEngine::addToSceneGraph(QQuickTextNode *parentNode,
if (range.first < otherRange.second && range.second > otherRange.first) {
int start = qMax(range.first, otherRange.first);
int end = qMin(range.second, otherRange.second);
- rangeLength -= end - start;
+ rangeLength -= end - start + 1;
if (rangeLength == 0)
break;
}