mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
fixes twitch emotes position
changes the position in unicodepoints to position in char16 array (qstring)
This commit is contained in:
parent
27eb2d8abc
commit
d2e43d78fc
2 changed files with 16 additions and 28 deletions
|
@ -174,11 +174,18 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
if (iterator != this->tags.end())
|
||||
{
|
||||
QStringList emoteString = iterator.value().toString().split('/');
|
||||
|
||||
std::vector<int> correctPositions;
|
||||
for (int i = 0; i < this->originalMessage_.size(); ++i) {
|
||||
if (!this->originalMessage_.at(i).isLowSurrogate()) {
|
||||
correctPositions.push_back(i);
|
||||
}
|
||||
}
|
||||
for (QString emote : emoteString)
|
||||
{
|
||||
this->appendTwitchEmote(emote, twitchEmotes);
|
||||
this->appendTwitchEmote(emote, twitchEmotes, correctPositions);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
auto app = getApp();
|
||||
const auto &phrases = app->ignores->phrases.getVector();
|
||||
|
@ -186,15 +193,6 @@ MessagePtr TwitchMessageBuilder::build()
|
|||
[&message = this->originalMessage_](int pos, int len,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>>
|
||||
&twitchEmotes) mutable {
|
||||
int emotePos = 0;
|
||||
for(int i = 0; i < pos; ++i) {
|
||||
++emotePos;
|
||||
if (message.at(i).isLowSurrogate()) {
|
||||
--emotePos;
|
||||
}
|
||||
}
|
||||
pos = emotePos;
|
||||
|
||||
auto it =
|
||||
std::partition(twitchEmotes.begin(), twitchEmotes.end(),
|
||||
[pos, len](const auto &item) {
|
||||
|
@ -461,17 +459,7 @@ void TwitchMessageBuilder::addWords(
|
|||
variant);
|
||||
}
|
||||
|
||||
for (int j = 0; j < word.size(); j++)
|
||||
{
|
||||
i++;
|
||||
|
||||
if (word.at(j).isHighSurrogate())
|
||||
{
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
i += word.size() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -944,7 +932,8 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg)
|
|||
|
||||
void TwitchMessageBuilder::appendTwitchEmote(
|
||||
const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec)
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec,
|
||||
std::vector<int> & correctPositions)
|
||||
{
|
||||
auto app = getApp();
|
||||
if (!emote.contains(':'))
|
||||
|
@ -972,8 +961,8 @@ void TwitchMessageBuilder::appendTwitchEmote(
|
|||
return;
|
||||
}
|
||||
|
||||
auto start = coords.at(0).toInt();
|
||||
auto end = coords.at(1).toInt();
|
||||
auto start = correctPositions[coords.at(0).toInt()];
|
||||
auto end = correctPositions[coords.at(1).toInt()];
|
||||
|
||||
if (start >= end || start < 0 || end > this->originalMessage_.length())
|
||||
{
|
||||
|
|
|
@ -55,9 +55,8 @@ private:
|
|||
void appendUsername();
|
||||
void parseHighlights(bool isPastMsg);
|
||||
|
||||
void appendTwitchEmote(
|
||||
const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec);
|
||||
void appendTwitchEmote(const QString &emote,
|
||||
std::vector<std::tuple<int, EmotePtr, EmoteName>> &vec, std::vector<int> &correctPositions);
|
||||
Outcome tryAppendEmote(const EmoteName &name);
|
||||
|
||||
void addWords(
|
||||
|
|
Loading…
Reference in a new issue