Add line inserting

This commit is contained in:
Petr Mironychev
2024-09-01 21:41:46 +02:00
parent a974b0aa82
commit 4d9adf75ff
3 changed files with 42 additions and 3 deletions

View File

@ -19,6 +19,9 @@
#include "LLMSuggestion.hpp"
#include <texteditor/texteditor.h>
#include <utils/stringutils.h>
namespace QodeAssist {
LLMSuggestion::LLMSuggestion(const Completion &completion, QTextDocument *origin)
@ -63,8 +66,29 @@ bool LLMSuggestion::apply()
bool LLMSuggestion::applyWord(TextEditor::TextEditorWidget *widget)
{
Q_UNUSED(widget)
return apply();
return applyNextLine(widget);
}
bool LLMSuggestion::applyNextLine(TextEditor::TextEditorWidget *widget)
{
QTextCursor currentCursor = widget->textCursor();
const QString text = m_completion.text();
int endPos = currentCursor.position();
while (endPos < text.length() && !text[endPos].isSpace()) {
++endPos;
}
QString wordToInsert = text.left(endPos);
wordToInsert = wordToInsert.split('\n').first();
if (!wordToInsert.isEmpty()) {
currentCursor.insertText(wordToInsert);
widget->setTextCursor(currentCursor);
}
return false;
}
void LLMSuggestion::reset()