Fix bold/coloured usernames also formatting trailing punctuation (#2597)

This commit is contained in:
James Upjohn
2021-04-12 01:09:21 +12:00
committed by GitHub
parent 8adda902d1
commit 06ec230759
2 changed files with 31 additions and 10 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
- Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200, #2225) - Major: Added "Channel Filters". See https://wiki.chatterino.com/Filters/ for how they work or how to configure them. (#1748, #2083, #2090, #2200, #2225)
- Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001, #2316, #2342, #2376) - Major: Added Streamer Mode configuration (under `Settings -> General`), where you can select which features of Chatterino should behave differently when you are in Streamer Mode. (#2001, #2316, #2342, #2376)
- Major: Add `/settitle` and `/setgame` commands, originally made for Mm2PL/Dankerino. (#2534, #2609) - Major: Add `/settitle` and `/setgame` commands, originally made for Mm2PL/Dankerino. (#2534, #2609)
- Major: Color mentions to match the mentioned users. You can disable this by unchecking "Color @usernames" under `Settings -> General -> Advanced (misc.)`. (#1963, #2284) - Major: Color mentions to match the mentioned users. You can disable this by unchecking "Color @usernames" under `Settings -> General -> Advanced (misc.)`. (#1963, #2284, #2597)
- Major: Commands `/ignore` and `/unignore` have been renamed to `/block` and `/unblock` in order to keep consistency with Twitch's terms. (#2370) - Major: Commands `/ignore` and `/unignore` have been renamed to `/block` and `/unblock` in order to keep consistency with Twitch's terms. (#2370)
- Major: Added support for bit emotes - the ones you unlock after cheering to streamer. (#2550) - Major: Added support for bit emotes - the ones you unlock after cheering to streamer. (#2550)
- Minor: Added `/clearmessages` command - does what "Burger menu -> More -> Clear messages" does. (#2485) - Minor: Added `/clearmessages` command - does what "Burger menu -> More -> Clear messages" does. (#2485)
+30 -9
View File
@@ -484,6 +484,7 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
if (match.hasMatch()) if (match.hasMatch())
{ {
QString username = match.captured(1); QString username = match.captured(1);
auto originalTextColor = textColor;
if (this->twitchChannel != nullptr && getSettings()->colorUsernames) if (this->twitchChannel != nullptr && getSettings()->colorUsernames)
{ {
@@ -495,13 +496,23 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
} }
} }
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername, auto prefixedUsername = '@' + username;
this->emplace<TextElement>(prefixedUsername,
MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold) textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username}); ->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>(prefixedUsername,
MessageElementFlag::NonBoldUsername,
textColor)
->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>(string.remove(prefixedUsername),
MessageElementFlag::Text,
originalTextColor);
this->emplace<TextElement>(
string, MessageElementFlag::NonBoldUsername, textColor)
->setLink({Link::UserInfo, username});
return; return;
} }
} }
@@ -514,6 +525,8 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
if (match.hasMatch() && chatters->contains(username)) if (match.hasMatch() && chatters->contains(username))
{ {
auto originalTextColor = textColor;
if (getSettings()->colorUsernames) if (getSettings()->colorUsernames)
{ {
if (auto userColor = if (auto userColor =
@@ -524,13 +537,21 @@ void TwitchMessageBuilder::addTextOrEmoji(const QString &string_)
} }
} }
this->emplace<TextElement>(string, MessageElementFlag::BoldUsername, this->emplace<TextElement>(username,
MessageElementFlag::BoldUsername,
textColor, FontStyle::ChatMediumBold) textColor, FontStyle::ChatMediumBold)
->setLink({Link::UserInfo, username}); ->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>( this->emplace<TextElement>(
string, MessageElementFlag::NonBoldUsername, textColor) username, MessageElementFlag::NonBoldUsername, textColor)
->setLink({Link::UserInfo, username}); ->setLink({Link::UserInfo, username})
->setTrailingSpace(false);
this->emplace<TextElement>(string.remove(username),
MessageElementFlag::Text,
originalTextColor);
return; return;
} }
} }