ClangCodeModel: Fix dot-to-arrow completion with extra characters

We failed to overwrite existing characters that match the completion if
clangd also changes "." to "->" at the same time.
Note that it still doesn't work as expected if the cursor is after the
dot and before the extra character. I'm not sure yet how to fix that.

Fixes: QTCREATORBUG-27034
Change-Id: I852145fc41f34ab60d9e944783e822bc9505453b
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-02-10 14:01:14 +01:00
parent 756a67c563
commit ce27886eeb

View File

@@ -3230,7 +3230,8 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator,
QTextCursor cursor = manipulator.textCursorAt(rangeStart); QTextCursor cursor = manipulator.textCursorAt(rangeStart);
cursor.movePosition(QTextCursor::EndOfWord); cursor.movePosition(QTextCursor::EndOfWord);
const QString textAfterCursor = manipulator.textAt(currentPos, cursor.position() - currentPos); const QString textAfterCursor = manipulator.textAt(currentPos, cursor.position() - currentPos);
if (textToBeInserted != textAfterCursor if (currentPos < cursor.position()
&& textToBeInserted != textAfterCursor
&& textToBeInserted.indexOf(textAfterCursor, currentPos - rangeStart) >= 0) { && textToBeInserted.indexOf(textAfterCursor, currentPos - rangeStart) >= 0) {
currentPos = cursor.position(); currentPos = cursor.position();
} }