From c95f4d82769b9eb5836f0ffbf9f87e054c393cec Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 21 Jan 2020 20:41:09 +0100 Subject: Fix colors in typing display, when username contains emoji --- src/timeline/TimelineModel.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 54e054ec..65a6e470 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -1406,9 +1406,34 @@ TimelineModel::formatTypingUsers(const std::vector &users, QColor bg) QStringList uidWithoutLast; auto formatUser = [this, bg](const QString &user_id) -> QString { - return QString("%2") - .arg(userColor(user_id, bg).name()) - .arg(escapeEmoji(displayName(user_id).toHtmlEscaped())); + auto uncoloredUsername = escapeEmoji(displayName(user_id).toHtmlEscaped()); + QString prefix = QString("").arg(userColor(user_id, bg).name()); + + // color only parts that don't have a font already specified + QString coloredUsername; + int index = 0; + do { + auto startIndex = uncoloredUsername.indexOf(" 0 ? startIndex - index : -1) + + ""; + + auto endIndex = uncoloredUsername.indexOf("", startIndex); + if (endIndex > 0) + endIndex += sizeof("") - 1; + + if (endIndex - startIndex != 0) + coloredUsername += + uncoloredUsername.midRef(startIndex, endIndex - startIndex); + + index = endIndex; + } while (index > 0 && index < uncoloredUsername.size()); + + return coloredUsername; }; for (size_t i = 0; i + 1 < users.size(); i++) { -- cgit 1.5.1