From 79e4e2e6e106c472a79fd91e1e7c8816719914eb Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 21 Jan 2020 04:18:17 +0100 Subject: [PATCH] Improve emoji escaping --- src/Utils.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 5e8e1a1..ab8631f 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -39,13 +39,23 @@ utils::replaceEmoji(const QString &body) QSettings settings; QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + bool insideFontBlock = true; for (auto &code : utf32_string) { // TODO: Be more precise here. - if (code > 9000) - fmtBody += QString("") + - QString::fromUcs4(&code, 1) + ""; - else - fmtBody += QString::fromUcs4(&code, 1); + if ((code >= 0x2600 && code <= 0x27bf) || (code >= 0x1f300 && code <= 0x1f3ff) || + (code >= 0x1f000 && code <= 0x1f64f) || (code >= 0x1f680 && code <= 0x1f6ff)) { + if (!insideFontBlock) { + fmtBody += QString(""); + insideFontBlock = true; + } + + } else { + if (insideFontBlock) { + fmtBody += ""; + insideFontBlock = false; + } + } + fmtBody += QString::fromUcs4(&code, 1); } return fmtBody;