Don't complete the current item when pressing special characters (e.g. `;') if the completion is automatically triggered.

This commit is contained in:
Roberto Raggi
2010-07-19 10:25:55 +02:00
parent 615381a5b1
commit 7de836bf85
2 changed files with 14 additions and 10 deletions

View File

@@ -439,7 +439,7 @@ CppCodeCompletion::CppCodeCompletion(CppModelManager *manager)
m_editor(0), m_editor(0),
m_startPosition(-1), m_startPosition(-1),
m_shouldRestartCompletion(false), m_shouldRestartCompletion(false),
m_forcedCompletion(false), m_automaticCompletion(false),
m_completionOperator(T_EOF_SYMBOL), m_completionOperator(T_EOF_SYMBOL),
m_objcEnabled(true) m_objcEnabled(true)
{ {
@@ -639,18 +639,16 @@ bool CppCodeCompletion::shouldRestartCompletion()
bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor) bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
{ {
m_editor = editor; m_editor = editor;
m_automaticCompletion = false;
const int pos = editor->position(); const int pos = editor->position();
unsigned token = T_EOF_SYMBOL; unsigned token = T_EOF_SYMBOL;
if (startOfOperator(editor, pos, &token, /*want function call=*/ true) != pos) { if (startOfOperator(editor, pos, &token, /*want function call=*/ true) != pos) {
if (token == T_POUND) { if (token == T_POUND) {
if (TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget())) { int line, column;
QTextCursor tc(edit->document()); editor->convertPosition(pos, &line, &column);
tc.setPosition(pos); if (column != 1)
return tc.positionInBlock() == 1;
}
return false; return false;
} }
@@ -676,12 +674,14 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1));
const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx); const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);
if (!tk.isComment() && !tk.isLiteral()) if (!tk.isComment() && !tk.isLiteral()) {
m_automaticCompletion = true;
return true; return true;
} }
} }
} }
} }
}
return false; return false;
} }
@@ -1759,6 +1759,9 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
bool CppCodeCompletion::typedCharCompletes(const TextEditor::CompletionItem &item, QChar typedChar) bool CppCodeCompletion::typedCharCompletes(const TextEditor::CompletionItem &item, QChar typedChar)
{ {
if (m_automaticCompletion)
return false;
if (item.data.canConvert<QString>()) // snippet if (item.data.canConvert<QString>()) // snippet
return false; return false;
@@ -1948,6 +1951,7 @@ bool CppCodeCompletion::partiallyComplete(const QList<TextEditor::CompletionItem
void CppCodeCompletion::cleanup() void CppCodeCompletion::cleanup()
{ {
m_automaticCompletion = false;
m_completions.clear(); m_completions.clear();
// Set empty map in order to avoid referencing old versions of the documents // Set empty map in order to avoid referencing old versions of the documents

View File

@@ -147,7 +147,7 @@ private:
int m_startPosition; // Position of the cursor from which completion started int m_startPosition; // Position of the cursor from which completion started
bool m_shouldRestartCompletion; bool m_shouldRestartCompletion;
bool m_forcedCompletion; bool m_automaticCompletion;
unsigned m_completionOperator; unsigned m_completionOperator;
bool m_objcEnabled; bool m_objcEnabled;