mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-27 10:50:28 -04:00
Add line inserting
This commit is contained in:
parent
a974b0aa82
commit
4d9adf75ff
@ -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()
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
|
||||
bool apply() final;
|
||||
bool applyWord(TextEditor::TextEditorWidget *widget) final;
|
||||
bool applyNextLine(TextEditor::TextEditorWidget *widget);
|
||||
void reset() final;
|
||||
int position() final;
|
||||
|
||||
|
@ -54,18 +54,32 @@ public:
|
||||
{
|
||||
auto apply = addAction(Tr::tr("Apply (%1)").arg(QKeySequence(Qt::Key_Tab).toString()));
|
||||
connect(apply, &QAction::triggered, this, &QodeAssistCompletionToolTip::apply);
|
||||
|
||||
auto applyWord = addAction(Tr::tr("Apply Next Line (%1)")
|
||||
.arg(QKeySequence(QKeySequence::MoveToNextLine).toString()));
|
||||
connect(applyWord, &QAction::triggered, this, &QodeAssistCompletionToolTip::applyWord);
|
||||
qDebug() << "applyWord sequence" << applyWord->shortcut();
|
||||
}
|
||||
|
||||
private:
|
||||
void apply()
|
||||
{
|
||||
if (TextSuggestion *suggestion = m_editor->currentSuggestion()) {
|
||||
if (auto *suggestion = dynamic_cast<LLMSuggestion *>(m_editor->currentSuggestion())) {
|
||||
if (!suggestion->apply())
|
||||
return;
|
||||
}
|
||||
ToolTip::hide();
|
||||
}
|
||||
|
||||
void applyWord()
|
||||
{
|
||||
if (auto *suggestion = dynamic_cast<LLMSuggestion *>(m_editor->currentSuggestion())) {
|
||||
if (!suggestion->applyWord(m_editor))
|
||||
return;
|
||||
}
|
||||
ToolTip::hide();
|
||||
}
|
||||
|
||||
TextEditorWidget *m_editor;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user