Commit 7d1c9096 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Use both highlightingModeAt and highlightingMode

Using only one is a bad choice because it could be that it returns
ISO C++ for some location, but the snippet wants C++. This is just bad,
the user should not need to care about these details. Instead just use
the both.

(cherry picked from commit 4478e509)
parent cab17fbe
Pipeline #172412 passed with stage
in 2 minutes and 31 seconds
......@@ -71,9 +71,11 @@ void SnippetCompletionModel::completionInvoked(KTextEditor::View *view, const KT
void SnippetCompletionModel::initData(KTextEditor::View *view)
{
QString mode = view->document()->highlightingModeAt(view->cursorPosition());
if (mode.isEmpty()) {
mode = view->document()->highlightingMode();
QString posMode = view->document()->highlightingModeAt(view->cursorPosition());
QString docMode = view->document()->highlightingMode();
if (docMode.isEmpty() && posMode.isEmpty()) {
qWarning() << Q_FUNC_INFO << "Unexpected empty modes";
return;
}
beginResetModel();
......@@ -86,7 +88,11 @@ void SnippetCompletionModel::initData(KTextEditor::View *view)
continue;
}
SnippetRepository *repo = dynamic_cast<SnippetRepository *>(store->item(i, 0));
if (repo && (repo->fileTypes().isEmpty() || repo->fileTypes().contains(mode))) {
if (!repo) {
continue;
}
const QStringList fileTypes = repo->fileTypes();
if (fileTypes.isEmpty() || fileTypes.contains(docMode) || fileTypes.contains(posMode)) {
for (int j = 0; j < repo->rowCount(); ++j) {
if (Snippet *snippet = dynamic_cast<Snippet *>(repo->child(j))) {
m_snippets << new SnippetCompletionItem(snippet, repo);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment