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) {
|
||||
event.accepted = true
|
||||
completionMenu.listView.decrementCurrentIndex()
|
||||
autoAppeared = true;
|
||||
}
|
||||
event.accepted = false
|
||||
}
|
||||
@@ -295,6 +296,7 @@ ToolBar {
|
||||
if (chatBar.isCompleting) {
|
||||
event.accepted = true
|
||||
completionMenu.listView.incrementCurrentIndex()
|
||||
autoAppeared = true;
|
||||
}
|
||||
event.accepted = false
|
||||
}
|
||||
@@ -336,11 +338,18 @@ ToolBar {
|
||||
currentRoom.cachedInput = text
|
||||
autoAppeared = false;
|
||||
|
||||
const completionInfo = documentHandler.getAutocompletionInfo();
|
||||
const completionInfo = documentHandler.getAutocompletionInfo(isCompleting);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (completionInfo.type === ChatDocumentHandler.None) {
|
||||
isCompleting = false;
|
||||
return;
|
||||
@@ -359,9 +368,12 @@ ToolBar {
|
||||
isCompleting = false;
|
||||
return;
|
||||
}
|
||||
isCompleting = true
|
||||
autoAppeared = true;
|
||||
completionMenu.endPosition = cursorPosition
|
||||
|
||||
if (!isCompleting) {
|
||||
isCompleting = true
|
||||
autoAppeared = true;
|
||||
completionMenu.endPosition = cursorPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -503,8 +515,6 @@ ToolBar {
|
||||
|
||||
function complete() {
|
||||
documentHandler.replaceAutoComplete(completionMenu.currentDisplayText);
|
||||
completionMenu.model = null
|
||||
chatBar.isCompleting = false
|
||||
if (completionMenu.completionType === ChatDocumentHandler.User
|
||||
&& completionMenu.currentDisplayText.length > 0
|
||||
&& completionMenu.currentItem.userId.length > 0) {
|
||||
|
||||
@@ -123,7 +123,7 @@ void ChatDocumentHandler::setRoom(NeoChatRoom *room)
|
||||
Q_EMIT roomChanged();
|
||||
}
|
||||
|
||||
QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
||||
QVariantMap ChatDocumentHandler::getAutocompletionInfo(bool isAutocompleting)
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
|
||||
@@ -133,9 +133,6 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
||||
{"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 textBeforeCursor = text;
|
||||
@@ -167,10 +164,17 @@ QVariantMap ChatDocumentHandler::getAutocompletionInfo()
|
||||
};
|
||||
}
|
||||
|
||||
return QVariantMap{
|
||||
{"keyword", autoCompletePrefix},
|
||||
{"type", AutoCompletionType::Emoji},
|
||||
};
|
||||
if (!isAutocompleting) {
|
||||
return QVariantMap{
|
||||
{"keyword", autoCompletePrefix},
|
||||
{"type", AutoCompletionType::Emoji},
|
||||
};
|
||||
} else {
|
||||
return QVariantMap{
|
||||
{"type", AutoCompletionType::Ignore},
|
||||
{"keyword", autoCompletePrefix},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return QVariantMap{
|
||||
@@ -197,7 +201,7 @@ void ChatDocumentHandler::replaceAutoComplete(const QString &word)
|
||||
}
|
||||
}
|
||||
|
||||
cursor.insertHtml(word + " ");
|
||||
cursor.insertHtml(word);
|
||||
m_lastState = cursor.block().text();
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
/// This function will look at the current QTextCursor and determine if there
|
||||
/// is the possibility to autocomplete it.
|
||||
Q_INVOKABLE QVariantMap getAutocompletionInfo();
|
||||
Q_INVOKABLE QVariantMap getAutocompletionInfo(bool isAutocompleting);
|
||||
Q_INVOKABLE void replaceAutoComplete(const QString &word);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
Reference in New Issue
Block a user