forked from qt-creator/qt-creator
LanguageClient: redo completion replacement logic
Instead of trying some magic when applying completion items just replace the text from the current position back to the start of the word. Change-Id: I03ac0f8c9bced88d21bd51f9e5cfa0a3ea25025a Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -99,16 +99,11 @@ void LanguageClientCompletionItem::apply(TextDocumentManipulatorInterface &manip
|
||||
if (auto edit = m_item.textEdit()) {
|
||||
applyTextEdit(manipulator, *edit);
|
||||
} else {
|
||||
const QString textToInsert(m_item.insertText().value_or(text()));
|
||||
int length = 0;
|
||||
for (auto it = textToInsert.crbegin(); it != textToInsert.crend(); ++it) {
|
||||
auto ch = *it;
|
||||
if (ch == manipulator.characterAt(pos - length - 1))
|
||||
++length;
|
||||
else if (length != 0)
|
||||
length = 0;
|
||||
}
|
||||
manipulator.replace(pos - length, length, textToInsert);
|
||||
QTextCursor cursor = manipulator.textCursorAt(pos);
|
||||
cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
|
||||
manipulator.replace(cursor.position(),
|
||||
cursor.selectionEnd() - cursor.selectionStart(),
|
||||
m_item.insertText().value_or(m_item.label()));
|
||||
}
|
||||
|
||||
if (auto additionalEdits = m_item.additionalTextEdits()) {
|
||||
|
||||
Reference in New Issue
Block a user