From ce27886eebe9809afcdc49a17806e8c3a81d585e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 10 Feb 2022 14:01:14 +0100 Subject: [PATCH] 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: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/clangcodemodel/clangdclient.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/clangcodemodel/clangdclient.cpp b/src/plugins/clangcodemodel/clangdclient.cpp index 5988d04d40d..c3240846904 100644 --- a/src/plugins/clangcodemodel/clangdclient.cpp +++ b/src/plugins/clangcodemodel/clangdclient.cpp @@ -3230,7 +3230,8 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator, QTextCursor cursor = manipulator.textCursorAt(rangeStart); cursor.movePosition(QTextCursor::EndOfWord); const QString textAfterCursor = manipulator.textAt(currentPos, cursor.position() - currentPos); - if (textToBeInserted != textAfterCursor + if (currentPos < cursor.position() + && textToBeInserted != textAfterCursor && textToBeInserted.indexOf(textAfterCursor, currentPos - rangeStart) >= 0) { currentPos = cursor.position(); }