fix(editor): use editor snapshot for SQL execution
This commit is contained in:
1 parent
4dbd1c7cc8
commit
6e7035823a
5 files changed
+43
-18
No files matched your search
@@ -8,7 +8,7 @@ import { search as cmSearch } from "@codemirror/search";
|
||||
import EditorSearchPanel from "./EditorSearchPanel.vue";
|
||||
import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";
|
||||
import { copyToClipboard } from "@/lib/clipboard";
|
||||
import { resolveExecutableSql } from "@/lib/sqlExecutionTarget";
|
||||
import { resolveExecutableSql, type SqlExecutionSnapshot } from "@/lib/sqlExecutionTarget";
|
||||
import { formatSqlText, type SqlFormatDialect } from "@/lib/sqlFormatter";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
@@ -64,7 +64,7 @@ const emit = defineEmits<{
|
||||
selectionChange: [value: string];
|
||||
cursorChange: [pos: number];
|
||||
formatError: [message: string];
|
||||
execute: [sql: string];
|
||||
execute: [snapshot: SqlExecutionSnapshot];
|
||||
save: [];
|
||||
clickTable: [tableName: string];
|
||||
viewTableData: [tableName: string];
|
||||
@@ -288,7 +288,7 @@ function handleTab(view: EditorViewType): boolean {
|
||||
}
|
||||
|
||||
function executeCurrentSql() {
|
||||
if (view.value) emit("execute", executableSqlFromView(view.value));
|
||||
if (view.value) emit("execute", sqlExecutionSnapshotFromView(view.value));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -461,6 +461,14 @@ function executableSqlFromView(currentView: EditorViewType): string {
|
||||
return resolveExecutableSql(currentView.state.doc.toString(), selectedSqlFromView(currentView));
|
||||
}
|
||||
|
||||
function sqlExecutionSnapshotFromView(currentView: EditorViewType): SqlExecutionSnapshot {
|
||||
return {
|
||||
fullSql: currentView.state.doc.toString(),
|
||||
selectedSql: selectedSqlFromView(currentView),
|
||||
cursorPos: currentView.state.selection.main.head,
|
||||
};
|
||||
}
|
||||
|
||||
function identifierRangeAt(sql: string, pos: number): { from: number; to: number; text: string } | null {
|
||||
const isIdentifierChar = (ch: string | undefined) => !!ch && /[\w$.]/.test(ch);
|
||||
if (!isIdentifierChar(sql[pos]) && !isIdentifierChar(sql[pos - 1])) return null;
|
||||
|
||||
@@ -54,6 +54,7 @@ import { tableMetaForDataTab } from "@/lib/tableDataTabMeta";
|
||||
import { formatShortcut } from "@/lib/shortcutRegistry";
|
||||
import { effectiveDatabaseTypeForConnection } from "@/lib/jdbcDialect";
|
||||
import { chartableColumnIndexes } from "@/lib/chartData";
|
||||
import type { SqlExecutionOverride } from "@/lib/sqlExecutionTarget";
|
||||
import { useTabScroll } from "@/composables/useTabScroll";
|
||||
import type { QueryTab, ConnectionConfig, TableInfoTab } from "@/types/database";
|
||||
import type { SqlFormatDialect } from "@/lib/sqlFormatter";
|
||||
@@ -101,7 +102,7 @@ const props = defineProps<{
|
||||
const emit = defineEmits<{
|
||||
"update:activeOutputView": [value: "result" | "summary" | "explain" | "chart"];
|
||||
fixWithAi: [errorMessage: string];
|
||||
execute: [sqlOverride?: string];
|
||||
execute: [sqlOverride?: SqlExecutionOverride];
|
||||
saveSql: [];
|
||||
cancel: [];
|
||||
explain: [];
|
||||
@@ -522,7 +523,7 @@ defineExpose({ focusSearch, refreshData, handleModRTarget });
|
||||
@viewport-change="emit('editorViewportChange', activeTab.id, $event)"
|
||||
@selection-state-change="emit('editorSelectionStateChange', activeTab.id, $event)"
|
||||
@format-error="emit('formatError')"
|
||||
@execute="emit('execute')"
|
||||
@execute="emit('execute', $event)"
|
||||
@save="emit('saveSql')"
|
||||
@click-table="onHandleClickTable"
|
||||
@view-table-data="onHandleViewTableData"
|
||||
|
||||
Reference in new issue
Block a user