Fix erroneous copying of emotes (twitch emotes in particular)

Fix #514
This commit is contained in:
Rasmus Karlsson 2018-06-24 16:29:30 +00:00
parent fc0e89edf3
commit 355b80680d
5 changed files with 31 additions and 2 deletions

View file

@ -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

View file

@ -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;

View file

@ -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 += " ";

View file

@ -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));
}
}

View file

@ -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("&lt;", "<");
cleanCode.replace("&gt;", ">");
newEmoteData.image1x = new messages::Image(getEmoteLink(id, "1.0"), 1, emoteName,
_emoteName + "<br/>Twitch Emote 1x");
newEmoteData.image1x->setCopyString(cleanCode);
newEmoteData.image2x = new messages::Image(getEmoteLink(id, "2.0"), .5, emoteName,
_emoteName + "<br/>Twitch Emote 2x");
newEmoteData.image2x->setCopyString(cleanCode);
newEmoteData.image3x = new messages::Image(getEmoteLink(id, "3.0"), .25, emoteName,
_emoteName + "<br/>Twitch Emote 3x");
newEmoteData.image3x->setCopyString(cleanCode);
return newEmoteData;
});
}