Fix emojis being split by rainbows

This commit is contained in:
Nicolas Werner 2021-03-28 20:41:08 +02:00
parent 326f48d87f
commit edaeb3ccde
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -517,18 +517,20 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
QTextBoundaryFinder tbf(QTextBoundaryFinder::BoundaryType::Grapheme, QTextBoundaryFinder tbf(QTextBoundaryFinder::BoundaryType::Grapheme,
nodeText); nodeText);
while ((boundaryEnd = tbf.toNextBoundary()) != -1) { while ((boundaryEnd = tbf.toNextBoundary()) != -1) {
charIdx++;
// Split text to get current char // Split text to get current char
auto curChar = auto curChar =
nodeText.midRef(boundaryStart, boundaryEnd - boundaryStart); nodeText.midRef(boundaryStart, boundaryEnd - boundaryStart);
boundaryStart = boundaryEnd; boundaryStart = boundaryEnd;
// Don't rainbowify whitespaces // Don't rainbowify whitespaces
if (curChar.trimmed().isEmpty()) { if (curChar.trimmed().isEmpty() ||
buf.append(curChar.toString()); codepointIsEmoji(curChar.toUcs4().first())) {
buf.append(curChar);
continue; continue;
} }
// get correct color for char index // get correct color for char index
auto color = QColor::fromHsvF(1.0 / textLen * charIdx, 1.0, 1.0); auto color = QColor::fromHsvF((charIdx - 1.0) / textLen, 1.0, 1.0);
// format color for HTML // format color for HTML
auto colorString = color.name(QColor::NameFormat::HexRgb); auto colorString = color.name(QColor::NameFormat::HexRgb);
// create HTML element for current char // create HTML element for current char
@ -537,8 +539,6 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
.arg(curChar); .arg(curChar);
// append colored HTML element to buffer // append colored HTML element to buffer
buf.append(curCharColored); buf.append(curCharColored);
charIdx++;
} }
// create HTML_INLINE node to prevent HTML from being escaped // create HTML_INLINE node to prevent HTML from being escaped