feat(editor): send selected SQL to AI panel

This commit is contained in:
gggaiitx authored and GitHub committed 2026-07-09 18:12:27 +08:00
1 parent f590a727a0
commit 482f7421be
13 files changed
+84 -5

No files matched your search

@@ -1656,7 +1656,12 @@ function triggerAction(action: AiAction, instruction?: string) {
send();
}
defineExpose({ triggerAction });
function setPrompt(text: string) {
prompt.value = text;
nextTick(() => promptTextareaRef.value?.focus());
}
defineExpose({ triggerAction, setPrompt });
const messageRenderer = computed(() => {
const appearance = aiCodeAppearance.value;
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, onActivated, onDeactivated, watch, shallowRef, computed, nextTick } from "vue";
import { CaseLower, CaseUpper, FileCode, PencilRuler, Play, Copy, Table2, TextSelect } from "@lucide/vue";
import { CaseLower, CaseUpper, FileCode, PencilRuler, Play, Copy, Sparkles, Table2, TextSelect } from "@lucide/vue";
import { useI18n } from "vue-i18n";
import type { CompletionContext } from "@codemirror/autocomplete";
import type { EditorView as EditorViewType } from "@codemirror/view";
@@ -103,6 +103,7 @@ const emit = defineEmits<{
closeColumnPanel: [];
viewportChange: [viewport: { scrollTop: number; scrollLeft: number }];
selectionStateChange: [selection: { anchor: number; head: number }];
sendSelectionToAi: [sql: string];
}>();
const editorRef = ref<HTMLDivElement>();
@@ -884,6 +885,15 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => {
icon: Copy,
shortcut: "Mod+C",
},
{
label: t("editor.contextMenu.sendToAi"),
action: () => {
if (selectedSql.value.trim()) emit("sendSelectionToAi", selectedSql.value);
},
disabled: !canCopySelectedSql.value,
icon: Sparkles,
shortcut: shortcuts.sendSelectionToAi,
},
{
label: t("editor.contextMenu.uppercaseSelection"),
action: () => convertSelectedSqlCase("upper"),
@@ -945,6 +955,11 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
void pasteClipboardAsSqlInCondition();
return true;
}),
...binding(shortcuts.sendSelectionToAi, (currentView) => {
const sql = selectedSqlFromView(currentView);
if (sql.trim()) emit("sendSelectionToAi", sql);
return true;
}),
]),
) ?? [],
codeMirrorKeymap.of(
@@ -123,6 +123,7 @@ const props = defineProps<{
const emit = defineEmits<{
"update:activeOutputView": [value: "result" | "summary" | "explain" | "chart"];
fixWithAi: [errorMessage: string];
sendSelectionToAi: [sql: string];
execute: [sqlOverride?: SqlExecutionOverride];
saveSql: [];
cancel: [];
@@ -759,6 +760,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget, requestQueryEditorExe
:initial-selection="activeTab.editorSelection"
@update:model-value="emit('editorUpdate', activeTab.id, $event)"
@selection-change="emit('editorSelectionChange', $event)"
@send-selection-to-ai="emit('sendSelectionToAi', $event)"
@cursor-change="emit('editorCursorChange', $event)"
@viewport-change="emit('editorViewportChange', activeTab.id, $event)"
@selection-state-change="emit('editorSelectionStateChange', activeTab.id, $event)"