Commit aeaaa392 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Use the completion case sensitivity settings also for relevance

Avoids some annoyance for people using case-sensitive completion, when
unrelated completions items would get higher relevance because they
start with the typed string when matched case-insensitively.

In case-insensitive mode, a case-sensitive prefix match now does get a
higher relevance than a case-insensitive match.

Reviewed-by: con
parent f5a893bc
......@@ -1493,10 +1493,17 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
}
const QRegExp regExp(keyRegExp, m_caseSensitivity);
const bool hasKey = !key.isEmpty();
foreach (TextEditor::CompletionItem item, m_completions) {
if (regExp.indexIn(item.text) == 0) {
item.relevance = (key.length() > 0 &&
item.text.startsWith(key, Qt::CaseInsensitive)) ? 1 : 0;
if (hasKey) {
if (item.text.startsWith(key, Qt::CaseSensitive)) {
item.relevance = 2;
} else if (m_caseSensitivity == Qt::CaseInsensitive
&& item.text.startsWith(key, Qt::CaseInsensitive)) {
item.relevance = 1;
}
}
(*completions) << item;
}
}
......
Markdown is supported
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