ClangCodeModel: Prevent adding an already-present closing quote

... when doing completion for header includes.

Fixes: QTCREATORBUG-31103
Change-Id: Ic2d4eb4abce4f6d0f7d08b0ff0f5e0f54669eb65
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2024-06-25 11:45:16 +02:00
parent 8405b384a3
commit a48fcfecd4

View File

@@ -359,8 +359,14 @@ void ClangdCompletionItem::apply(TextDocumentManipulatorInterface &manipulator,
}
// Avoid inserting characters that are already there
// For include file completions, also consider a possibly pre-existing
// closing quote or angle bracket.
QTextCursor cursor = manipulator.textCursorAt(rangeStart);
cursor.movePosition(QTextCursor::EndOfWord);
if (kind == CompletionItemKind::File && !textToBeInserted.isEmpty()
&& textToBeInserted.right(1) == manipulator.textAt(cursor.position(), 1)) {
cursor.setPosition(cursor.position() + 1);
}
const QString textAfterCursor = manipulator.textAt(currentPos, cursor.position() - currentPos);
if (currentPos < cursor.position()
&& textToBeInserted != textAfterCursor