Keep completion behavior similar to before
* Use tab to jump to the next completion item * Space to accept change
This commit is contained in:
@@ -287,6 +287,7 @@ ToolBar {
|
|||||||
if (chatBar.isCompleting) {
|
if (chatBar.isCompleting) {
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
completionMenu.listView.decrementCurrentIndex()
|
completionMenu.listView.decrementCurrentIndex()
|
||||||
|
autoAppeared = true;
|
||||||
}
|
}
|
||||||
event.accepted = false
|
event.accepted = false
|
||||||
}
|
}
|
||||||
@@ -295,6 +296,7 @@ ToolBar {
|
|||||||
if (chatBar.isCompleting) {
|
if (chatBar.isCompleting) {
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
completionMenu.listView.incrementCurrentIndex()
|
completionMenu.listView.incrementCurrentIndex()
|
||||||
|
autoAppeared = true;
|
||||||
}
|
}
|
||||||
event.accepted = false
|
event.accepted = false
|
||||||
}
|
}
|
||||||
@@ -336,11 +338,18 @@ ToolBar {
|
|||||||
currentRoom.cachedInput = text
|
currentRoom.cachedInput = text
|
||||||
autoAppeared = false;
|
autoAppeared = false;
|
||||||
|
|
||||||
const completionInfo = documentHandler.getAutocompletionInfo();
|
const completionInfo = documentHandler.getAutocompletionInfo(isCompleting);
|
||||||
|
|
||||||
if (completionInfo.type === ChatDocumentHandler.Ignore) {
|
if (completionInfo.type === ChatDocumentHandler.Ignore) {
|
||||||
|
if (completionInfo.keyword) {
|
||||||
|
// custom emojis
|
||||||
|
const idx = completionMenu.currentIndex;
|
||||||
|
completionMenu.model = Array.from(chatBar.customEmojiModel.filterModel(completionInfo.keyword)).concat(EmojiModel.filterModel(completionInfo.keyword))
|
||||||
|
completionMenu.currentIndex = idx;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completionInfo.type === ChatDocumentHandler.None) {
|
if (completionInfo.type === ChatDocumentHandler.None) {
|
||||||
isCompleting = false;
|
isCompleting = false;
|
||||||
return;
|
return;
|
||||||
@@ -359,9 +368,12 @@ ToolBar {
|
|||||||
isCompleting = false;
|
isCompleting = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isCompleting = true
|
|
||||||
autoAppeared = true;
|
if (!isCompleting) {
|
||||||
completionMenu.endPosition = cursorPosition
|
isCompleting = true
|
||||||
|
autoAppeared = true;
|
||||||
|
completionMenu.endPosition = cursorPosition
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -503,8 +515,6 @@ ToolBar {
|
|||||||
|
|
||||||
function complete() {
|
function complete() {
|
||||||
documentHandler.replaceAutoComplete(completionMenu.currentDisplayText);
|
documentHandler.replaceAutoComplete(completionMenu.currentDisplayText);
|
||||||
completionMenu.model = null
|
|
||||||
chatBar.isCompleting = false
|
|
||||||
if (completionMenu.completionType === ChatDocumentHandler.User
|
if (completionMenu.completionType === ChatDocumentHandler.User
|
||||||
&& completionMenu.currentDisplayText.length > 0
|
&& completionMenu.currentDisplayText.length > 0
|
||||||
&& completionMenu.currentItem.userId.length > 0) {
|
&& completionMenu.currentItem.userId.length > 0) {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ void ChatDocumentHandler::setRoom(NeoChatRoom *room)
|
|||||||
Q_EMIT roomChanged();
|
Q_EMIT roomChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
QVariantMap ChatDocumentHandler::getAutocompletionInfo(bool isAutocompleting)
|
||||||
{
|
{
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
|
|
||||||
@@ -133,9 +133,6 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
|||||||
{"type", AutoCompletionType::Ignore},
|
{"type", AutoCompletionType::Ignore},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (m_cursorPosition != m_autoCompleteBeginPosition && m_cursorPosition != m_autoCompleteEndPosition) {
|
|
||||||
// we moved our cursor, so cancel autocompletion
|
|
||||||
}
|
|
||||||
|
|
||||||
QString text = cursor.block().text();
|
QString text = cursor.block().text();
|
||||||
QString textBeforeCursor = text;
|
QString textBeforeCursor = text;
|
||||||
@@ -167,10 +164,17 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariantMap{
|
if (!isAutocompleting) {
|
||||||
{"keyword", autoCompletePrefix},
|
return QVariantMap{
|
||||||
{"type", AutoCompletionType::Emoji},
|
{"keyword", autoCompletePrefix},
|
||||||
};
|
{"type", AutoCompletionType::Emoji},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return QVariantMap{
|
||||||
|
{"type", AutoCompletionType::Ignore},
|
||||||
|
{"keyword", autoCompletePrefix},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariantMap{
|
return QVariantMap{
|
||||||
@@ -197,7 +201,7 @@ void ChatDocumentHandler::replaceAutoComplete(const QString &word)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.insertHtml(word + " ");
|
cursor.insertHtml(word);
|
||||||
m_lastState = cursor.block().text();
|
m_lastState = cursor.block().text();
|
||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
/// This function will look at the current QTextCursor and determine if there
|
/// This function will look at the current QTextCursor and determine if there
|
||||||
/// is the possibility to autocomplete it.
|
/// is the possibility to autocomplete it.
|
||||||
Q_INVOKABLE QVariantMap getAutocompletionInfo();
|
Q_INVOKABLE QVariantMap getAutocompletionInfo(bool isAutocompleting);
|
||||||
Q_INVOKABLE void replaceAutoComplete(const QString &word);
|
Q_INVOKABLE void replaceAutoComplete(const QString &word);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|||||||
Reference in New Issue
Block a user