diff options
| author | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-07-24 13:48:21 +0200 |
|---|---|---|
| committer | Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> | 2009-07-24 13:52:49 +0200 |
| commit | 5271117e5be82b5ff80bb972e1638ee98c5b9725 (patch) | |
| tree | 42b7a900fd46fd26c7410d6c37384cf4b1fcf254 /src/plugins/cpptools/cppcodecompletion.cpp | |
| parent | b49d715a1c36e6b1a42866f04a85b31b39a8b893 (diff) | |
| download | qt-creator-5271117e5be82b5ff80bb972e1638ee98c5b9725.tar.gz | |
Avoid inserting another closing character when completing includes
When a closing character is already there, it shouldn't be appended.
Done by generalizing the same code for automatically inserted brackets
after C++ symbols.
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
| -rw-r--r-- | src/plugins/cpptools/cppcodecompletion.cpp | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index f3c9a9d53f..8fac72b95e 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -1209,7 +1209,6 @@ bool CppCodeCompletion::completeInclude(const QTextCursor &cursor) // Make completion for all relevant includes if (ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject()) { - QStringList items; QStringList includePaths = m_manager->projectInfo(project).includePaths; const QString currentFilePath = QFileInfo(m_editor->file()->fileName()).path(); if (!includePaths.contains(currentFilePath)) @@ -1221,22 +1220,17 @@ bool CppCodeCompletion::completeInclude(const QTextCursor &cursor) realPath += QLatin1Char('/'); realPath += directoryPrefix; } - items.append(m_manager->includesInPath(realPath)); - } - - if (!items.isEmpty()) { - foreach (const QString &itemText, items) { + foreach (const QString &itemText, m_manager->includesInPath(realPath)) { TextEditor::CompletionItem item(this); item.m_text += itemText; // TODO: Icon for include files item.m_icon = m_icons.keywordIcon(); m_completions.append(item); } - return true; } } - return false; + return !m_completions.isEmpty(); } void CppCodeCompletion::completeNamespace(const QList<Symbol *> &candidates, @@ -1443,15 +1437,16 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) symbol = item.m_data.value<Symbol *>(); QString toInsert; + QString extraChars; int extraLength = 0; if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) { toInsert = item.m_text; - toInsert += QLatin1Char(')'); + extraChars += QLatin1Char(')'); } else if (m_completionOperator == T_STRING_LITERAL || m_completionOperator == T_ANGLE_STRING_LITERAL) { toInsert = item.m_text; if (!toInsert.endsWith(QLatin1Char('/'))) - toInsert += QLatin1Char((m_completionOperator == T_ANGLE_STRING_LITERAL) ? '>' : '"'); + extraChars += QLatin1Char((m_completionOperator == T_ANGLE_STRING_LITERAL) ? '>' : '"'); } else { toInsert = item.m_text; @@ -1459,8 +1454,6 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) //<< overview.prettyType(symbol->type()); if (m_autoInsertBrackets && symbol && symbol->type()) { - QString extraChars; - if (Function *function = symbol->type()->asFunctionType()) { // If the member is a function, automatically place the opening parenthesis, // except when it might take template parameters. @@ -1487,22 +1480,21 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) } } } - - // Avoid inserting characters that are already there - for (int i = 0; i < extraChars.length(); ++i) { - const QChar a = extraChars.at(i); - const QChar b = m_editor->characterAt(m_editor->position() + i); - if (a == b) - ++extraLength; - else - break; - } - - toInsert += extraChars; } + } + // Avoid inserting characters that are already there + for (int i = 0; i < extraChars.length(); ++i) { + const QChar a = extraChars.at(i); + const QChar b = m_editor->characterAt(m_editor->position() + i); + if (a == b) + ++extraLength; + else + break; } + toInsert += extraChars; + // Insert the remainder of the name int length = m_editor->position() - m_startPosition + extraLength; m_editor->setCurPos(m_startPosition); |
