forked from qt-creator/qt-creator
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
This commit is contained in:
@@ -1493,10 +1493,17 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
|
|||||||
}
|
}
|
||||||
const QRegExp regExp(keyRegExp, m_caseSensitivity);
|
const QRegExp regExp(keyRegExp, m_caseSensitivity);
|
||||||
|
|
||||||
|
const bool hasKey = !key.isEmpty();
|
||||||
foreach (TextEditor::CompletionItem item, m_completions) {
|
foreach (TextEditor::CompletionItem item, m_completions) {
|
||||||
if (regExp.indexIn(item.text) == 0) {
|
if (regExp.indexIn(item.text) == 0) {
|
||||||
item.relevance = (key.length() > 0 &&
|
if (hasKey) {
|
||||||
item.text.startsWith(key, Qt::CaseInsensitive)) ? 1 : 0;
|
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;
|
(*completions) << item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user