From 342c909b340cb1bfbb95480fc79dcea21a470c83 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 3 Feb 2016 13:53:44 +0100 Subject: Qt Quick: Fix selection when mixing line breaks and line wraps The enabler for finding selection ranges in Qt Quick had two bugs which caused some selected text to disappear. Specifically, this was the case for selected text where a line contained both an explicit break and a break due to line wrapping. First of all, the glyphsEnd that is passed into glyphRunsWithInfo() is expected to be inclusive, since we are actually searching for its index in the log cluster array. We would in certain cases not find the glyph at all in the log clusters, thus the glyph run would be set to overlap with any glyph run coming after it in the same item. Second of all, we need to start searching at the correct position in the log clusters when searching for the correct rangeStart, since rangeStart is initialized with textPosition. Otherwise, we would in some cases never reach the start of the range, and rangeStart would be set to textPosition + textLength, which is the end of the range. Task-number: QTBUG-49596 Change-Id: I436ba3f1c7414d4f5044d9b70aa04c60b01755e4 Reviewed-by: Simon Hausmann --- src/gui/text/qtextlayout.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/gui/text/qtextlayout.cpp') diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 9e2a23a7f7..bc9c452ff7 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -2141,6 +2141,7 @@ static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine, QGlyphRunPrivate *d = QGlyphRunPrivate::get(glyphRun); int rangeStart = textPosition; + logClusters += textPosition; while (*logClusters != glyphsStart && rangeStart < textPosition + textLength) { ++logClusters; ++rangeStart; @@ -2325,16 +2326,16 @@ QList QTextLine::glyphRuns(int from, int length) const if (mainFontEngine->type() == QFontEngine::Multi) { QFontEngineMulti *multiFontEngine = static_cast(mainFontEngine); - int end = rtl ? glyphLayout.numGlyphs : 0; - int start = rtl ? end : 0; - int which = glyphLayout.glyphs[rtl ? start - 1 : end] >> 24; - for (; (rtl && start > 0) || (!rtl && end < glyphLayout.numGlyphs); + int start = rtl ? glyphLayout.numGlyphs : 0; + int end = start - 1; + int which = glyphLayout.glyphs[rtl ? start - 1 : end + 1] >> 24; + for (; (rtl && start > 0) || (!rtl && end < glyphLayout.numGlyphs - 1); rtl ? --start : ++end) { - const int e = glyphLayout.glyphs[rtl ? start - 1 : end] >> 24; + const int e = glyphLayout.glyphs[rtl ? start - 1 : end + 1] >> 24; if (e == which) continue; - QGlyphLayout subLayout = glyphLayout.mid(start, end - start); + QGlyphLayout subLayout = glyphLayout.mid(start, end - start + 1); multiFontEngine->ensureEngineAt(which); QGlyphRun::GlyphRunFlags subFlags = flags; @@ -2358,13 +2359,13 @@ QList QTextLine::glyphRuns(int from, int length) const } if (rtl) - end = start; + end = start - 1; else - start = end; + start = end + 1; which = e; } - QGlyphLayout subLayout = glyphLayout.mid(start, end - start); + QGlyphLayout subLayout = glyphLayout.mid(start, end - start + 1); multiFontEngine->ensureEngineAt(which); QGlyphRun::GlyphRunFlags subFlags = flags; -- cgit v1.2.3