mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(autocomplete): don't auto-complete own nick
In the process also remove the dependency of the auto completer on Core.
This commit is contained in:
parent
1ebcac4460
commit
f188409b8c
|
@ -183,3 +183,8 @@ void Group::setSelfName(const QString& name)
|
||||||
{
|
{
|
||||||
selfName = name;
|
selfName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Group::getSelfName() const
|
||||||
|
{
|
||||||
|
return selfName;
|
||||||
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
const ToxPk resolvePeerId(int peerId) const;
|
const ToxPk resolvePeerId(int peerId) const;
|
||||||
QString resolveToxId(const ToxPk& id) const;
|
QString resolveToxId(const ToxPk& id) const;
|
||||||
void setSelfName(const QString& name);
|
void setSelfName(const QString& name);
|
||||||
|
QString getSelfName() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void titleChangedByUser(uint32_t groupId, const QString& title);
|
void titleChangedByUser(uint32_t groupId, const QString& title);
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
#include "src/core/core.h"
|
|
||||||
#include "src/model/group.h"
|
#include "src/model/group.h"
|
||||||
#include "src/widget/tool/chattextedit.h"
|
#include "src/widget/tool/chattextedit.h"
|
||||||
|
|
||||||
|
@ -72,7 +71,11 @@ void TabCompleter::buildCompletionList()
|
||||||
QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)),
|
QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)),
|
||||||
Qt::CaseInsensitive);
|
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) {
|
if (regex.indexIn(name) > -1) {
|
||||||
SortableString lower = SortableString(name.toLower());
|
SortableString lower = SortableString(name.toLower());
|
||||||
completionMap[lower] = name;
|
completionMap[lower] = name;
|
||||||
|
@ -96,8 +99,9 @@ void TabCompleter::complete()
|
||||||
auto cur = msgEdit->textCursor();
|
auto cur = msgEdit->textCursor();
|
||||||
cur.setPosition(cur.selectionEnd());
|
cur.setPosition(cur.selectionEnd());
|
||||||
msgEdit->setTextCursor(cur);
|
msgEdit->setTextCursor(cur);
|
||||||
for (int i = 0; i < lastCompletionLength; ++i)
|
for (int i = 0; i < lastCompletionLength; ++i) {
|
||||||
msgEdit->textCursor().deletePreviousChar();
|
msgEdit->textCursor().deletePreviousChar();
|
||||||
|
}
|
||||||
|
|
||||||
// insert completion
|
// insert completion
|
||||||
msgEdit->insertPlainText(*nextCompletion);
|
msgEdit->insertPlainText(*nextCompletion);
|
||||||
|
@ -127,12 +131,6 @@ void TabCompleter::reset()
|
||||||
// this determines the sort order
|
// this determines the sort order
|
||||||
bool TabCompleter::SortableString::operator<(const SortableString& other) const
|
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 thisTime = thisUser->lastChannelActivity(_currentBufferId);
|
||||||
QDateTime thatTime = thatUser->lastChannelActivity(_currentBufferId);
|
QDateTime thatTime = thatUser->lastChannelActivity(_currentBufferId);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user