Commit 2e56fe23 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Avoid opening completion box in some unwanted situations

Don't automatically trigger the completion when editing a word or when
in a comment or string.
parent 15e655b7
......@@ -656,14 +656,32 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
return true;
} else if (completionSettings().m_completionTrigger == TextEditor::AutomaticCompletion) {
// Trigger completion after three characters of a name have been typed
// Trigger completion after three characters of a name have been typed, when not editing an existing name
QChar characterUnderCursor = editor->characterAt(pos);
if (!characterUnderCursor.isLetterOrNumber()) {
const int startOfName = findStartOfName(pos);
if (pos - startOfName == 3) {
const QChar firstCharacter = editor->characterAt(startOfName);
if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_'))
if (firstCharacter.isLetter() || firstCharacter == QLatin1Char('_')) {
// Finally check that we're not inside a comment or string (code copied from startOfOperator)
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
QTextCursor tc(edit->textCursor());
SimpleLexer tokenize;
const QList<Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1));
const Token tk = (tokenIdx == -1) ? Token() :;
if (!tk.isComment() && !tk.isLiteral())
return true;
return false;
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