From 355b80680d5103e57f71e91095b5d6b24d51db19 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 24 Jun 2018 16:29:30 +0000 Subject: [PATCH] Fix erroneous copying of emotes (twitch emotes in particular) Fix #514 --- src/messages/image.cpp | 15 +++++++++++++++ src/messages/image.hpp | 4 ++++ src/messages/layouts/messagelayoutelement.cpp | 2 +- src/messages/messageelement.cpp | 3 ++- src/providers/twitch/twitchemotes.cpp | 9 +++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/messages/image.cpp b/src/messages/image.cpp index 2aa887a98..3ebc1a5ea 100644 --- a/src/messages/image.cpp +++ b/src/messages/image.cpp @@ -1,6 +1,7 @@ #include "messages/image.hpp" #include "application.hpp" +#include "debug/log.hpp" #include "singletons/emotemanager.hpp" #include "singletons/ircmanager.hpp" #include "singletons/windowmanager.hpp" @@ -209,6 +210,15 @@ const QString &Image::getName() const return this->name; } +const QString &Image::getCopyString() const +{ + if (this->copyString.isEmpty()) { + return this->name; + } + + return this->copyString; +} + const QString &Image::getTooltip() const { return this->tooltip; @@ -258,5 +268,10 @@ int Image::getScaledHeight() const getApp()->settings->emoteScale.getValue()); } +void Image::setCopyString(const QString &newCopyString) +{ + this->copyString = newCopyString; +} + } // namespace messages } // namespace chatterino diff --git a/src/messages/image.hpp b/src/messages/image.hpp index b3966ffdd..89b7ae3d0 100644 --- a/src/messages/image.hpp +++ b/src/messages/image.hpp @@ -25,6 +25,7 @@ public: qreal getScale() const; const QString &getUrl() const; const QString &getName() const; + const QString &getCopyString() const; const QString &getTooltip() const; const QMargins &getMargin() const; bool isAnimated() const; @@ -34,6 +35,8 @@ public: int getHeight() const; int getScaledHeight() const; + void setCopyString(const QString &newCopyString); + private: struct FrameData { QPixmap *image; @@ -50,6 +53,7 @@ private: QString url; QString name; + QString copyString; QString tooltip; bool animated = false; QMargins margin; diff --git a/src/messages/layouts/messagelayoutelement.cpp b/src/messages/layouts/messagelayoutelement.cpp index 788e23ee1..2cf46f07f 100644 --- a/src/messages/layouts/messagelayoutelement.cpp +++ b/src/messages/layouts/messagelayoutelement.cpp @@ -74,7 +74,7 @@ ImageLayoutElement::ImageLayoutElement(MessageElement &_creator, Image *_image, void ImageLayoutElement::addCopyTextToString(QString &str, int from, int to) const { - str += this->image->getName(); + str += this->image->getCopyString(); if (this->hasTrailingSpace()) { str += " "; diff --git a/src/messages/messageelement.cpp b/src/messages/messageelement.cpp index 8b1f4c732..ff9562527 100644 --- a/src/messages/messageelement.cpp +++ b/src/messages/messageelement.cpp @@ -85,7 +85,8 @@ EmoteElement::EmoteElement(const util::EmoteData &_data, MessageElement::Flags f { if (_data.isValid()) { this->setTooltip(data.image1x->getTooltip()); - this->textElement.reset(new TextElement(_data.image1x->getName(), MessageElement::Misc)); + this->textElement.reset( + new TextElement(_data.image1x->getCopyString(), MessageElement::Misc)); } } diff --git a/src/providers/twitch/twitchemotes.cpp b/src/providers/twitch/twitchemotes.cpp index a20945b2d..b43ab3484 100644 --- a/src/providers/twitch/twitchemotes.cpp +++ b/src/providers/twitch/twitchemotes.cpp @@ -120,13 +120,22 @@ util::EmoteData TwitchEmotes::getEmoteById(const QString &id, const QString &emo return _twitchEmoteFromCache.getOrAdd(id, [&emoteName, &_emoteName, &id] { util::EmoteData newEmoteData; + auto cleanCode = cleanUpCode(emoteName); + cleanCode.replace("<", "<"); + cleanCode.replace(">", ">"); newEmoteData.image1x = new messages::Image(getEmoteLink(id, "1.0"), 1, emoteName, _emoteName + "
Twitch Emote 1x"); + newEmoteData.image1x->setCopyString(cleanCode); + newEmoteData.image2x = new messages::Image(getEmoteLink(id, "2.0"), .5, emoteName, _emoteName + "
Twitch Emote 2x"); + newEmoteData.image2x->setCopyString(cleanCode); + newEmoteData.image3x = new messages::Image(getEmoteLink(id, "3.0"), .25, emoteName, _emoteName + "
Twitch Emote 3x"); + newEmoteData.image3x->setCopyString(cleanCode); + return newEmoteData; }); }