diff --git a/src/App.vue b/src/App.vue index cd361157b..e60c37f57 100644 --- a/src/App.vue +++ b/src/App.vue @@ -168,6 +168,25 @@ function toggleLocale() { setLocale(currentLocale() === "zh-CN" ? "en" : "zh-CN" function openGitHub() { openUrl("https://github.com/t8y2/dbx"); } function openMcpGuide() { openUrl("https://github.com/t8y2/dbx/blob/main/docs/mcp-guide.md"); } +function ensureQueryTab(): string { + const tab = activeTab.value; + if (tab && tab.mode === "query") return tab.id; + const connId = connectionStore.activeConnectionId || connectionStore.connections[0]?.id || ""; + const db = tab?.database || ""; + return queryStore.createTab(connId, db, undefined, "query"); +} + +function onAiReplaceSql(sql: string) { + const tabId = ensureQueryTab(); + queryStore.updateSql(tabId, sql); +} + +function onAiExecuteSql(sql: string) { + const tabId = ensureQueryTab(); + queryStore.updateSql(tabId, sql); + nextTick(() => tryExecute()); +} + function handleKeydown(e: KeyboardEvent) { if (isCloseTabShortcut(e)) { e.preventDefault(); @@ -280,8 +299,8 @@ onUnmounted(() => { window.removeEventListener("keydown", handleKeydown, true);