forked from qt-creator/qt-creator
Completion: improve complete in the middle
Backport the master commit (cherry-pick). Apply clang fix to the old code model Do not replace the text after cursor if the proposal does not contain it or if proposal matches 100% the text after it Task-number: QTCREATORBUG-18471 Change-Id: I10c90580d46d2d2c899dc1ed8fe4d7df0531691a Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -76,6 +76,7 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
int extraLength = 0;
|
||||
int cursorOffset = 0;
|
||||
bool setAutoCompleteSkipPos = false;
|
||||
int currentPosition = manipulator.currentPosition();
|
||||
|
||||
bool autoParenthesesEnabled = true;
|
||||
if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
||||
@@ -124,7 +125,7 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
|
||||
// If the function doesn't return anything, automatically place the semicolon,
|
||||
// unless we're doing a scope completion (then it might be function definition).
|
||||
const QChar characterAtCursor = manipulator.characterAt(manipulator.currentPosition());
|
||||
const QChar characterAtCursor = manipulator.characterAt(currentPosition);
|
||||
bool endWithSemicolon = m_typedCharacter == QLatin1Char(';')/*
|
||||
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
|
||||
const QChar semicolon = m_typedCharacter.isNull() ? QLatin1Char(';') : m_typedCharacter;
|
||||
@@ -181,7 +182,13 @@ void ClangAssistProposalItem::apply(TextEditor::TextDocumentManipulatorInterface
|
||||
// Avoid inserting characters that are already there
|
||||
QTextCursor cursor = manipulator.textCursorAt(basePosition);
|
||||
cursor.movePosition(QTextCursor::EndOfWord);
|
||||
const int currentPosition = cursor.position();
|
||||
const QString textAfterCursor = manipulator.textAt(currentPosition,
|
||||
cursor.position() - currentPosition);
|
||||
|
||||
if (textToBeInserted != textAfterCursor
|
||||
&& textToBeInserted.indexOf(textAfterCursor, currentPosition - basePosition) >= 0) {
|
||||
currentPosition = cursor.position();
|
||||
}
|
||||
|
||||
for (int i = 0; i < extraCharacters.length(); ++i) {
|
||||
const QChar a = extraCharacters.at(i);
|
||||
|
||||
Reference in New Issue
Block a user