diff options
author | Liang Qi <liang.qi@qt.io> | 2017-03-21 19:07:53 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-03-21 19:07:53 +0100 |
commit | 65faf4565595d91996ddec4af25af5e97c7f0317 (patch) | |
tree | a7415e90db3fa1e46f638e1c31d2f2b9a5d0ec4a /src/widgets/widgets/qwidgettextcontrol.cpp | |
parent | a9383ef99a29c333a1edd32695ddc29ea0ba805d (diff) | |
parent | 26bc4ac5cb56ce8f2d3d10125fa9c6a72140573a (diff) |
Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts:
src/plugins/platforms/eglfs/eglfs-plugin.pro
Change-Id: Id76cdbb41b7758572a3b8ea4dcb40d49bac968db
Diffstat (limited to 'src/widgets/widgets/qwidgettextcontrol.cpp')
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index f5672bd87a..dacb4806ce 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -2052,16 +2052,59 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) preeditCursor = a.start; hideCursor = !a.length; } else if (a.type == QInputMethodEvent::TextFormat) { - QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); + QTextCharFormat f = cursor.charFormat(); + f.merge(qvariant_cast<QTextFormat>(a.value).toCharFormat()); if (f.isValid()) { QTextLayout::FormatRange o; o.start = a.start + cursor.position() - block.position(); o.length = a.length; o.format = f; - overrides.append(o); + + // Make sure list is sorted by start index + QVector<QTextLayout::FormatRange>::iterator it = overrides.end(); + while (it != overrides.begin()) { + QVector<QTextLayout::FormatRange>::iterator previous = it - 1; + if (o.start >= previous->start) { + overrides.insert(it, o); + break; + } + it = previous; + } + + if (it == overrides.begin()) + overrides.prepend(o); } } } + + if (cursor.charFormat().isValid()) { + int start = cursor.position() - block.position(); + int end = start + e->preeditString().length(); + + QVector<QTextLayout::FormatRange>::iterator it = overrides.begin(); + while (it != overrides.end()) { + QTextLayout::FormatRange range = *it; + int rangeStart = range.start; + if (rangeStart > start) { + QTextLayout::FormatRange o; + o.start = start; + o.length = rangeStart - start; + o.format = cursor.charFormat(); + it = overrides.insert(it, o) + 1; + } + + ++it; + start = range.start + range.length; + } + + if (start < end) { + QTextLayout::FormatRange o; + o.start = start; + o.length = end - start; + o.format = cursor.charFormat(); + overrides.append(o); + } + } layout->setFormats(overrides); cursor.endEditBlock(); |