From 454b6bcb70027ef44cda0e60e18dcc98efcd34fd Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 14 May 2018 17:28:00 +0200 Subject: [PATCH] added username autocompletions with @ --- src/util/completionmodel.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/util/completionmodel.cpp b/src/util/completionmodel.cpp index 6cf8a0fa..65bec3b1 100644 --- a/src/util/completionmodel.cpp +++ b/src/util/completionmodel.cpp @@ -92,23 +92,28 @@ void CompletionModel::addString(const QString &str, TaggedString::Type type) this->emotes.insert({str + " ", type}); } -void CompletionModel::addUser(const QString &str) +void CompletionModel::addUser(const QString &username) { - auto ts = this->createUser(str + " "); - // Always add a space at the end of completions - std::pair::iterator, bool> p = this->emotes.insert(ts); - if (!p.second) { - // No inseration was made, figure out if we need to replace the username. + auto add = [this](const QString &str) { + auto ts = this->createUser(str + " "); + // Always add a space at the end of completions + std::pair::iterator, bool> p = this->emotes.insert(ts); + if (!p.second) { + // No inseration was made, figure out if we need to replace the username. - if (p.first->str > ts.str) { - // Replace lowercase version of name with mixed-case version - this->emotes.erase(p.first); - auto result2 = this->emotes.insert(ts); - assert(result2.second); - } else { - p.first->timeAdded = std::chrono::steady_clock::now(); + if (p.first->str > ts.str) { + // Replace lowercase version of name with mixed-case version + this->emotes.erase(p.first); + auto result2 = this->emotes.insert(ts); + assert(result2.second); + } else { + p.first->timeAdded = std::chrono::steady_clock::now(); + } } - } + }; + + add(username); + add("@" + username); } void CompletionModel::ClearExpiredStrings()