From 63eaf3b94cc747c752b0e9040c97820d109056db Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 11 Aug 2018 17:35:46 +0200 Subject: [PATCH] fixed not being able to select text backwards --- src/messages/Selection.hpp | 13 ++++--------- src/providers/twitch/TwitchAccount.cpp | 10 ++++++++++ src/providers/twitch/TwitchAccount.hpp | 8 +++++--- src/providers/twitch/TwitchMessageBuilder.cpp | 7 +++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/messages/Selection.hpp b/src/messages/Selection.hpp index 8eefc3a33..7cffebbec 100644 --- a/src/messages/Selection.hpp +++ b/src/messages/Selection.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include namespace chatterino { @@ -23,19 +24,13 @@ struct SelectionItem { bool operator<(const SelectionItem &b) const { - if (this->messageIndex < b.messageIndex) { - return true; - } - if (this->messageIndex == b.messageIndex && - this->charIndex < b.charIndex) { - return true; - } - return false; + return std::tie(this->messageIndex, this->charIndex) < + std::tie(b.messageIndex, b.charIndex); } bool operator>(const SelectionItem &b) const { - return this->operator!=(b) && b.operator<(*this); + return b.operator<(*this); } bool operator==(const SelectionItem &b) const diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 95a8d37eb..0258c6e72 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -78,6 +78,16 @@ const QString &TwitchAccount::getUserId() const return this->userId_; } +QColor TwitchAccount::color() +{ + return this->color_.get(); +} + +void TwitchAccount::setColor(QColor color) +{ + this->color_.set(color); +} + bool TwitchAccount::setOAuthClient(const QString &newClientID) { if (this->oauthClient_.compare(newClientID) == 0) { diff --git a/src/providers/twitch/TwitchAccount.hpp b/src/providers/twitch/TwitchAccount.hpp index 21dfbac63..c59ca9d38 100644 --- a/src/providers/twitch/TwitchAccount.hpp +++ b/src/providers/twitch/TwitchAccount.hpp @@ -1,5 +1,6 @@ #pragma once +#include "common/Atomic.hpp" #include "common/UniqueAccess.hpp" #include "controllers/accounts/Account.hpp" #include "messages/Emote.hpp" @@ -66,9 +67,11 @@ public: const QString &getUserName() const; const QString &getOAuthToken() const; const QString &getOAuthClient() const; - const QString &getUserId() const; + QColor color(); + void setColor(QColor color); + // Attempts to update the users OAuth Client ID // Returns true if the value has changed, otherwise false bool setOAuthClient(const QString &newClientID); @@ -104,8 +107,6 @@ public: void loadEmotes(); AccessGuard accessEmotes() const; - QColor color; - private: void parseEmotes(const rapidjson::Document &document); void loadEmoteSetData(std::shared_ptr emoteSet); @@ -115,6 +116,7 @@ private: QString userName_; QString userId_; const bool isAnon_; + Atomic color_; mutable std::mutex ignoresMutex_; std::set ignores_; diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 7bc5ce0f2..e475b724d 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -457,7 +457,7 @@ void TwitchMessageBuilder::appendUsername() app->themes->messages.textColors.system, FontStyle::ChatMedium); - QColor selfColor = currentUser->color; + QColor selfColor = currentUser->color(); if (!selfColor.isValid()) { selfColor = app->themes->messages.textColors.system; } @@ -490,7 +490,7 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) QString currentUsername = currentUser->getUserName(); if (this->ircMessage->nick() == currentUsername) { - currentUser->color = this->usernameColor_; + currentUser->setColor(this->usernameColor_); // Do nothing. Highlights cannot be triggered by yourself return; } @@ -645,8 +645,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) flags = MessageElementFlag::BttvEmote; } else if ((emote = getApp()->emotes->ffz.global(name))) { flags = MessageElementFlag::FfzEmote; - } else if (twitchChannel && - (emote = this->twitchChannel->ffzEmote(name))) { + } else if (twitchChannel && (emote = this->twitchChannel->ffzEmote(name))) { flags = MessageElementFlag::FfzEmote; }