Skip to content
Snippets Groups Projects
Commit 373bfb05 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: On completion, avoid adding : or . again if already present.

parent 4f6dc35a
No related branches found
No related tags found
No related merge requests found
......@@ -902,7 +902,25 @@ void CodeCompletion::complete(const TextEditor::CompletionItem &item)
}
}
const int length = m_editor->position() - m_startPosition;
QString replacableChars;
if (toInsert.endsWith(QLatin1String(": ")))
replacableChars = QLatin1String(": ");
else if (toInsert.endsWith(QLatin1String(".")))
replacableChars = QLatin1String(".");
int replacedLength = 0;
// Avoid inserting characters that are already there
for (int i = 0; i < replacableChars.length(); ++i) {
const QChar a = replacableChars.at(i);
const QChar b = m_editor->characterAt(m_editor->position() + i);
if (a == b)
++replacedLength;
else
break;
}
const int length = m_editor->position() - m_startPosition + replacedLength;
m_editor->setCurPos(m_startPosition);
m_editor->replace(length, toInsert);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment