feat: trigger completion of commands on the input of backlash / char

This commit is contained in:
Srevin Saju
2021-05-01 13:30:24 +03:00
parent ee595ed374
commit 6575d23072
4 changed files with 17 additions and 1 deletions

View File

@@ -29,6 +29,7 @@ add_executable(neochat
login.cpp
stickerevent.cpp
chatboxhelper.cpp
commandmodel.cpp
../res.qrc
)

View File

@@ -149,7 +149,7 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
};
}
if (autoCompletePrefix.startsWith("@") || autoCompletePrefix.startsWith(":")) {
if (autoCompletePrefix.startsWith("@") || autoCompletePrefix.startsWith(":") || autoCompletePrefix.startsWith("/")) {
m_autoCompleteBeginPosition = textBeforeCursor.lastIndexOf(" ") + 1; // 1 == space
if (autoCompletePrefix.startsWith("@")) {
@@ -159,6 +159,14 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
{"type", AutoCompletionType::User},
};
}
if (autoCompletePrefix.startsWith("/")) {
return QVariantMap{
{"keyword", autoCompletePrefix},
{"type", AutoCompletionType::Command},
};
}
return QVariantMap{
{"keyword", autoCompletePrefix},
{"type", AutoCompletionType::Emoji},

View File

@@ -27,6 +27,7 @@ public:
enum AutoCompletionType {
User,
Emoji,
Command,
None,
Ignore,
};

View File

@@ -27,6 +27,7 @@
#include "chatboxhelper.h"
#include "chatdocumenthandler.h"
#include "clipboard.h"
#include "commandmodel.h"
#include "controller.h"
#include "csapi/joining.h"
#include "csapi/leaving.h"
@@ -148,6 +149,11 @@ int main(int argc, char *argv[])
Q_UNUSED(engine2);
return new EmojiModel();
});
qmlRegisterSingletonType<CommandModel>("org.kde.neochat", 1, 0, "CommandModel", [](QQmlEngine *engine2, QJSEngine *scriptEngine) -> QObject * {
Q_UNUSED(scriptEngine);
Q_UNUSED(engine2);
return new CommandModel();
});
qmlRegisterType<SortFilterRoomListModel>("org.kde.neochat", 1, 0, "SortFilterRoomListModel");
qmlRegisterType<DevicesModel>("org.kde.neochat", 1, 0, "DevicesModel");
qmlRegisterUncreatableType<RoomMessageEvent>("org.kde.neochat", 1, 0, "RoomMessageEvent", "ENUM");