summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-03-18 15:49:58 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>2016-04-08 09:44:06 +0000
commit24914b1acbfc5e45768dd1465b9e3f3e61185829 (patch)
tree3266c75d3bef19a803ca4fbfcbcfdc03238ad096 /src/gui/text
parentf6eadcd60178b1a16224d557b8945020164eba7d (diff)
Qt Quick: Fix bug for selections with line wraps and breaks
This fixes yet another bug where the selection spans both line wraps and explicit line breaks. Offsetting the log clusters by the text position in 342c909b340cb1bfbb95480fc79dcea21a470c83 was not entirely correct, because in some cases the script item will refer to a specific part of the string, as indicated by si.position, while iterator.itemStart is in the context of the full string. In this case, the log cluster array pointer we use refers to the script item's part of the array, i.e. it is already offset by si.position. Therefore, we must offset the logClusters pointer by the text position *relative* to the current script item. Previously we would actually offset by si.position twice in cases where si.position != 0. We want the text range to refer to the full string, though, so it can be compared to other text ranges later. However, in some cases when we are requesting only part of a script item, then iterator.itemStart does not correspond to relativeFrom, so in order for the text range search to work, we must pass in the text positions we are using [relativeFrom, relativeTo], though offset by si.position so that it refers to the full string and not just the part addressed by the script item. Task-number: QTBUG-51759 Change-Id: Ib69856d6d3bc1dd501db94c9d295623f436d122c Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextlayout.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index bc9c452ff7..aca475a581 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2141,7 +2141,6 @@ static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine,
QGlyphRunPrivate *d = QGlyphRunPrivate::get(glyphRun);
int rangeStart = textPosition;
- logClusters += textPosition;
while (*logClusters != glyphsStart && rangeStart < textPosition + textLength) {
++logClusters;
++rangeStart;
@@ -2350,9 +2349,9 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
width,
glyphsStart + start,
glyphsStart + end,
- logClusters,
- iterator.itemStart,
- iterator.itemLength));
+ logClusters + relativeFrom,
+ relativeFrom + si.position,
+ relativeTo - relativeFrom + 1));
for (int i = 0; i < subLayout.numGlyphs; ++i) {
QFixed justification = QFixed::fromFixed(subLayout.justifications[i].space_18d6);
pos.rx() += (subLayout.advances[i] + justification).toReal();
@@ -2380,9 +2379,9 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
width,
glyphsStart + start,
glyphsStart + end,
- logClusters,
- iterator.itemStart,
- iterator.itemLength);
+ logClusters + relativeFrom,
+ relativeFrom + si.position,
+ relativeTo - relativeFrom + 1);
if (!glyphRun.isEmpty())
glyphRuns.append(glyphRun);
} else {
@@ -2396,9 +2395,9 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
width,
glyphsStart,
glyphsEnd,
- logClusters,
- iterator.itemStart,
- iterator.itemLength);
+ logClusters + relativeFrom,
+ relativeFrom + si.position,
+ relativeTo - relativeFrom + 1);
if (!glyphRun.isEmpty())
glyphRuns.append(glyphRun);
}