diff options
author | David Schulz <david.schulz@qt.io> | 2019-05-03 15:04:40 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2019-05-06 09:01:15 +0000 |
commit | 5eca6c031fbeddf063935a2ea6b4e08f76c73719 (patch) | |
tree | 4d813b06700b969c18ca774bebf835127f50c6b0 /src/plugins/languageclient | |
parent | a7f1fc2d6bafee180f95fdf35669d06455b88ada (diff) |
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>
Diffstat (limited to 'src/plugins/languageclient')
-rw-r--r-- | src/plugins/languageclient/languageclientcompletionassist.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/plugins/languageclient/languageclientcompletionassist.cpp b/src/plugins/languageclient/languageclientcompletionassist.cpp index 71f9e0d2646..710cc8e1f33 100644 --- a/src/plugins/languageclient/languageclientcompletionassist.cpp +++ b/src/plugins/languageclient/languageclientcompletionassist.cpp @@ -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()) { |