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

Be smarter about CamelCase when doing case-insensitive completion

Even when an upper case character can also match a lower case one, it
should only be treated as a CamelCase match when the matched character
is also upper case. This avoids some false positives.

Also, the part that allows a word in a CamelCase identifier to be
truncated should never be matched case-insensitively.
parent 96707f0b
......@@ -1444,23 +1444,27 @@ void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completio
QString keyRegExp;
keyRegExp += QLatin1Char('^');
bool first = true;
const QLatin1String wordContinuation("[a-z0-9_]*");
foreach (const QChar &c, key) {
if (c.isUpper() && !first)
keyRegExp += QLatin1String("[a-z0-9_]*");
if (m_caseSensitivity == CaseInsensitive ||
(m_caseSensitivity == FirstLetterCaseSensitive && !first)) {
if (m_caseSensitivity == FirstLetterCaseSensitive && !first) {
keyRegExp += QLatin1Char('[');
keyRegExp += QRegExp::escape(c.toLower());
keyRegExp += QLatin1String("(?:");
if (c.isUpper() && !first)
keyRegExp += wordContinuation;
keyRegExp += QRegExp::escape(c.toUpper());
keyRegExp += QLatin1Char(']');
keyRegExp += "|";
keyRegExp += QRegExp::escape(c.toLower());
keyRegExp += QLatin1Char(')');
} else {
if (c.isUpper() && !first)
keyRegExp += wordContinuation;
keyRegExp += QRegExp::escape(c);
}
first = false;
}
const QRegExp regExp(keyRegExp, (m_caseSensitivity == CaseInsensitive)
? Qt::CaseInsensitive : Qt::CaseSensitive);
const QRegExp regExp(keyRegExp);
foreach (TextEditor::CompletionItem item, m_completions) {
if (regExp.indexIn(item.text) == 0) {
......
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