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

Taskn-number: QTCREATORBUG-7521

Change-Id: I7b8edb93d143f599c93a82c82bf2c0d49c8e49e9
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Leandro Melo
2012-06-12 11:25:37 +02:00
parent 3e0d666f70
commit 93894ab160

View File

@@ -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);