Keep completion behavior similar to before

* Use tab to jump to the next completion item
* Space to accept change
This commit is contained in:
Carl Schwan
2021-06-17 00:09:16 +02:00
parent 6898670499
commit 768fd74361
3 changed files with 30 additions and 16 deletions

View File

@@ -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();
}