Commit 93894ab1 authored by Leandro Melo's avatar Leandro Melo
Browse files

C++: Do not reuse content in completion if it's unfinished identifier



Taskn-number: QTCREATORBUG-7521

Change-Id: I7b8edb93d143f599c93a82c82bf2c0d49c8e49e9
Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent 3e0d666f
......@@ -337,18 +337,24 @@ void CppAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor *e
--cursorOffset;
}
// Avoid inserting characters that are already there
const int endsPosition = editor->position(TextEditor::ITextEditor::EndOfLine);
const QString text = editor->textAt(editor->position(), endsPosition - editor->position());
// Determine the length of characters that should just be kept on the editor, but do
// not consider content that ends as an identifier (which could be undesired).
const int lineEnd = editor->position(TextEditor::ITextEditor::EndOfLine);
const QString inEditor = editor->textAt(editor->position(), lineEnd - editor->position());
int existLength = 0;
if (!text.isEmpty()) {
// Calculate the exist length in front of the extra chars
if (!inEditor.isEmpty()) {
existLength = toInsert.length() - (editor->position() - basePosition);
while (!text.startsWith(toInsert.right(existLength))) {
const int inEditorLength = inEditor.length();
while (inEditorLength < existLength
|| (!inEditor.startsWith(toInsert.right(existLength))
|| (inEditorLength > existLength
&& (inEditor.at(existLength).isLetterOrNumber()
|| inEditor.at(existLength) == QLatin1Char('_'))))) {
if (--existLength == 0)
break;
}
}
for (int i = 0; i < extraChars.length(); ++i) {
const QChar a = extraChars.at(i);
const QChar b = editor->characterAt(editor->position() + i + existLength);
......
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