fix(editor): execute manually selected sql from the toolbar

This commit is contained in:
jearhe authored and GitHub committed 2026-09-13 13:27:12 +08:00
1 parent 28206f2963
commit 1137cab7f4
9 files changed
+310 -33

No files matched your search

+21 -20
View File
@@ -776,15 +776,17 @@ const executableSql = computed(() => {
: "";
});
async function resolveActiveExecutableSql(snapshot?: SqlExecutionSnapshot) {
const tab = activeTab.value;
return tab
? await resolveExecutableSqlWithBackend(snapshot?.fullSql ?? tab.sql, snapshot?.selectedSql ?? selectedSql.value, {
mode: settingsStore.editorSettings.executeMode,
cursorPos: snapshot?.cursorPos ?? cursorPos.value,
databaseType: activeConnection.value?.db_type,
})
: "";
async function resolveActiveExecutableSql(snapshot?: SqlExecutionSnapshot, executionTab?: QueryTab) {
const tab = executionTab ?? activeTab.value;
if (!tab) return "";
const connection = connectionStore.getConfig(tab.connectionId) ?? activeConnection.value;
const selection = tab.editorSelection;
const fallbackSelectedSql = tab.id === activeTab.value?.id ? selectedSql.value : selection && selection.anchor !== selection.head ? tab.sql.slice(Math.min(selection.anchor, selection.head), Math.max(selection.anchor, selection.head)) : "";
return await resolveExecutableSqlWithBackend(snapshot?.fullSql ?? tab.sql, snapshot?.selectedSql ?? fallbackSelectedSql, {
mode: settingsStore.editorSettings.executeMode,
cursorPos: snapshot?.cursorPos ?? (tab.id === activeTab.value?.id ? cursorPos.value : (selection?.head ?? 0)),
databaseType: connection?.db_type,
});
}
const blockDangerousRedisCommands = ref(true);
@@ -835,22 +837,21 @@ const {
onExecutionCancelled: (editorViewportRequestId) => contentAreaRef.value?.cancelQueryEditorExecutionViewport(editorViewportRequestId),
});
function captureActiveEditorExecutionSnapshot() {
const snapshot = contentAreaRef.value?.captureQueryEditorExecutionSnapshot?.();
pendingToolbarExecutionSnapshot.value = snapshot ? { ...snapshot, tabId: activeTab.value?.id } : undefined;
function captureActiveEditorExecutionSnapshot(tabId: string) {
const snapshot = contentAreaRef.value?.captureQueryEditorExecutionSnapshot?.(tabId);
pendingToolbarExecutionSnapshot.value = snapshot ? { ...snapshot, tabId } : undefined;
}
function requestActiveEditorExecute(source?: "pointer" | "keyboard") {
function requestActiveEditorExecute(source?: "pointer" | "keyboard", tabId?: string) {
const snapshot = pendingToolbarExecutionSnapshot.value;
pendingToolbarExecutionSnapshot.value = undefined;
if (source === "pointer") {
if (snapshot) {
void tryExecute(snapshot, { tabId: snapshot.tabId ?? activeTab.value?.id });
return;
}
const targetTabId = tabId ?? (source === "pointer" ? snapshot?.tabId : undefined);
if (source === "pointer" && snapshot && snapshot.tabId === targetTabId) {
void tryExecute(snapshot, { tabId: targetTabId });
return;
}
if (contentAreaRef.value?.requestQueryEditorExecute?.()) return;
void tryExecute();
if (contentAreaRef.value?.requestQueryEditorExecute?.(targetTabId)) return;
void tryExecute(undefined, targetTabId ? { tabId: targetTabId } : undefined);
}
function requestActiveEditorExecuteInNewResultTab() {