From 48a5250194ce830aaa32de883a5f38f5dd617316 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 6 Aug 2026 14:56:13 +0200 Subject: [PATCH] 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. --- kate/ollie_kate.cpp | 37 +++++++++++++++++++++++++++++++++++++ kate/ollie_kate.h | 1 + 2 files changed, 38 insertions(+) diff --git a/kate/ollie_kate.cpp b/kate/ollie_kate.cpp index 3ff83a2..126c17c 100644 --- a/kate/ollie_kate.cpp +++ b/kate/ollie_kate.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -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 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; diff --git a/kate/ollie_kate.h b/kate/ollie_kate.h index c0199fc..4ef6c87 100644 --- a/kate/ollie_kate.h +++ b/kate/ollie_kate.h @@ -68,6 +68,7 @@ private: void askAboutFile(); void explainSelection(); void submitSelectionPrompt(const QString &action); + void sendVerbatim(); void reviewDiff(); // Agent management