kate: add 'Send verbatim' context action
Sends selected text wrapped in a code fence with the appropriate language (derived from Kate's highlighting mode). Useful for pasting code snippets directly to the agent without any surrounding prompt text.
This commit is contained in:
parent
4acda0f7de
commit
48a5250194
|
|
@ -14,6 +14,7 @@
|
|||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QHash>
|
||||
#include <QKeyEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
|
|
@ -339,6 +340,11 @@ void OllieKateView::setupContextMenu(KTextEditor::View *view)
|
|||
QStringLiteral("Ollie: Document this"));
|
||||
docAction->setObjectName(QStringLiteral("ollie_ctx_doc"));
|
||||
connect(docAction, &QAction::triggered, this, [this]() { submitSelectionPrompt(QStringLiteral("Add documentation comments to")); });
|
||||
|
||||
auto *verbatimAction = menu->addAction(QIcon::fromTheme(QStringLiteral("document-send")),
|
||||
QStringLiteral("Ollie: Send verbatim"));
|
||||
verbatimAction->setObjectName(QStringLiteral("ollie_ctx_verbatim"));
|
||||
connect(verbatimAction, &QAction::triggered, this, &OllieKateView::sendVerbatim);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -415,6 +421,37 @@ void OllieKateView::submitSelectionPrompt(const QString &action)
|
|||
m_9p->write(agentPath() + "/prompt", prompt.toUtf8());
|
||||
}
|
||||
|
||||
void OllieKateView::sendVerbatim()
|
||||
{
|
||||
auto *view = m_mainWindow->activeView();
|
||||
if (!view || !view->selection()) return;
|
||||
|
||||
QString selection = view->selectionText();
|
||||
if (selection.isEmpty()) return;
|
||||
|
||||
ensureAgent();
|
||||
if (m_agentId.isEmpty()) return;
|
||||
|
||||
// Derive fence language from document highlighting mode
|
||||
QString mode = view->document()->highlightingMode().toLower();
|
||||
// Map common Kate highlighting names to fence languages
|
||||
static const QHash<QString, QString> modeMap = {
|
||||
{"c++", "cpp"}, {"c", "c"}, {"cmake", "cmake"},
|
||||
{"javascript", "javascript"}, {"typescript", "typescript"},
|
||||
{"python", "python"}, {"rust", "rust"}, {"go", "go"},
|
||||
{"bash", "bash"}, {"zsh", "bash"}, {"shell", "bash"},
|
||||
{"json", "json"}, {"yaml", "yaml"}, {"toml", "toml"},
|
||||
{"html", "html"}, {"css", "css"}, {"sql", "sql"},
|
||||
{"java", "java"}, {"kotlin", "kotlin"}, {"ruby", "ruby"},
|
||||
{"perl", "perl"}, {"lua", "lua"}, {"diff", "diff"},
|
||||
{"markdown", "markdown"}, {"xml", "xml"},
|
||||
};
|
||||
QString lang = modeMap.value(mode, mode);
|
||||
|
||||
QString prompt = "```" + lang + "\n" + selection + "\n```";
|
||||
m_9p->write(agentPath() + "/prompt", prompt.toUtf8());
|
||||
}
|
||||
|
||||
void OllieKateView::reviewDiff()
|
||||
{
|
||||
QString diff;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ private:
|
|||
void askAboutFile();
|
||||
void explainSelection();
|
||||
void submitSelectionPrompt(const QString &action);
|
||||
void sendVerbatim();
|
||||
void reviewDiff();
|
||||
|
||||
// Agent management
|
||||
|
|
|
|||
Reference in New Issue