From db7333e6bbbac53a144893965d1444a2e022f3b0 Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Wed, 26 May 2010 14:25:01 +0200 Subject: [PATCH] Sort the completion items as soon as we have them. --- src/plugins/cpptools/cppcodecompletion.cpp | 16 ++++++++-------- src/plugins/cpptools/cppcodecompletion.h | 3 ++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index f89d5df1057..88ca3b75587 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -445,7 +445,6 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager) m_completionOperator(T_EOF_SYMBOL), m_objcEnabled(true) { - m_sorted = false; } QIcon CppCodeCompletion::iconForSymbol(Symbol *symbol) const @@ -655,7 +654,14 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor) int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) { - m_sorted = false; + int index = startCompletionHelper(editor); + if (index != -1) + qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan); + return index; +} + +int CppCodeCompletion::startCompletionHelper(TextEditor::ITextEditable *editor) +{ TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget()); if (! edit) return -1; @@ -1592,11 +1598,6 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions() completions(&completionItems); - if (! m_sorted) { - qStableSort(completionItems.begin(), completionItems.end(), completionItemLessThan); - m_sorted = true; - } - // Remove duplicates QString lastKey; QList<TextEditor::CompletionItem> uniquelist; @@ -1741,7 +1742,6 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem void CppCodeCompletion::cleanup() { - m_sorted = false; m_completions.clear(); // Set empty map in order to avoid referencing old versions of the documents diff --git a/src/plugins/cpptools/cppcodecompletion.h b/src/plugins/cpptools/cppcodecompletion.h index 432f1f298ab..f7d1667f761 100644 --- a/src/plugins/cpptools/cppcodecompletion.h +++ b/src/plugins/cpptools/cppcodecompletion.h @@ -122,6 +122,8 @@ private: int findStartOfName(int pos = -1) const; + int startCompletionHelper(TextEditor::ITextEditable *editor); + int startCompletionInternal(TextEditor::BaseTextEditor *edit, const QString fileName, unsigned line, unsigned column, @@ -147,7 +149,6 @@ private: QPointer<FunctionArgumentWidget> m_functionArgumentWidget; QList<TextEditor::CompletionItem> m_completions; - bool m_sorted; }; } // namespace Internal -- GitLab