summaryrefslogtreecommitdiff
path: root/src/plugins/clangcodemodel
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2017-06-28 09:51:53 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2017-07-14 10:03:48 +0000
commit5a7a64b37da08267898c0e9fd02a1be1aab0f212 (patch)
treec2cfc1ae61e72036c2f18f906ffa90a4d2d4551e /src/plugins/clangcodemodel
parent6a4499205067732d5dadc626eb6af8b1f783b919 (diff)
downloadqt-creator-5a7a64b37da08267898c0e9fd02a1be1aab0f212.tar.gz
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>
Diffstat (limited to 'src/plugins/clangcodemodel')
-rw-r--r--src/plugins/clangcodemodel/clangassistproposalitem.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/plugins/clangcodemodel/clangassistproposalitem.cpp b/src/plugins/clangcodemodel/clangassistproposalitem.cpp
index 012ac9af5e..75dc40c671 100644
--- a/src/plugins/clangcodemodel/clangassistproposalitem.cpp
+++ b/src/plugins/clangcodemodel/clangassistproposalitem.cpp
@@ -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);