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

@@ -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(