feat: add autocompletion for commands

partially copied code from emojimodel.h
This commit is contained in:
Srevin Saju
2021-05-01 13:27:54 +03:00
parent 57684aa454
commit ee595ed374
2 changed files with 90 additions and 0 deletions

32
src/commandmodel.cpp Normal file
View File

@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2021 Srevin Saju <srevinsaju@sugarlabs.org>
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QDebug>
#include "commandmodel.h"
QVariantList CommandModel::filterModel(const QString &filter)
{
QVariantList result;
for (const QVariant &e : matrix) {
auto command = qvariant_cast<Command>(e);
if (command.command.startsWith(filter)) {
result.append(e);
if (result.length() > 10) {
return result;
}
}
}
return result;
}
// the help messages are taken from Element (web matrix client, app.element.io)
const QVariantList CommandModel::matrix = {
QVariant::fromValue(Command{"/join", "Join a given room with address"}),
QVariant::fromValue(Command{"/me", "Displays action"}),
};