Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(autocomplete): don't auto-complete own nick
Browse files Browse the repository at this point in the history
In the process also remove the dependency of the auto completer on Core.
  • Loading branch information
sudden6 committed Nov 22, 2018
1 parent 1ebcac4 commit f188409
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/model/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,8 @@ void Group::setSelfName(const QString& name)
{
selfName = name;
}

QString Group::getSelfName() const
{
return selfName;
}
1 change: 1 addition & 0 deletions src/model/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Group : public Contact
const ToxPk resolvePeerId(int peerId) const;
QString resolveToxId(const ToxPk& id) const;
void setSelfName(const QString& name);
QString getSelfName() const;

signals:
void titleChangedByUser(uint32_t groupId, const QString& title);
Expand Down
16 changes: 7 additions & 9 deletions src/widget/form/tabcompleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <QKeyEvent>
#include <QRegExp>

#include "src/core/core.h"
#include "src/model/group.h"
#include "src/widget/tool/chattextedit.h"

Expand Down Expand Up @@ -72,7 +71,11 @@ void TabCompleter::buildCompletionList()
QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)),
Qt::CaseInsensitive);

for (auto name : group->getPeerList()) {
const QString ownNick = group->getSelfName();
for (const auto& name : group->getPeerList()) {
if (name == ownNick) {
continue; // don't auto complete own name
}
if (regex.indexIn(name) > -1) {
SortableString lower = SortableString(name.toLower());
completionMap[lower] = name;
Expand All @@ -96,8 +99,9 @@ void TabCompleter::complete()
auto cur = msgEdit->textCursor();
cur.setPosition(cur.selectionEnd());
msgEdit->setTextCursor(cur);
for (int i = 0; i < lastCompletionLength; ++i)
for (int i = 0; i < lastCompletionLength; ++i) {
msgEdit->textCursor().deletePreviousChar();
}

// insert completion
msgEdit->insertPlainText(*nextCompletion);
Expand Down Expand Up @@ -127,12 +131,6 @@ void TabCompleter::reset()
// this determines the sort order
bool TabCompleter::SortableString::operator<(const SortableString& other) const
{
QString name = Core::getInstance()->getUsername();
if (this->contents == name)
return false;
else if (other.contents == name)
return true;

/* QDateTime thisTime = thisUser->lastChannelActivity(_currentBufferId);
QDateTime thatTime = thatUser->lastChannelActivity(_currentBufferId);
Expand Down

0 comments on commit f188409

Please sign in to comment.