mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 16:18:55 +00:00
fix(editor): route save shortcut by context
This commit is contained in:
+8
-9
@@ -35,7 +35,12 @@ import * as api from "@/lib/api";
|
||||
import { resolveDefaultDatabase } from "@/lib/defaultDatabase";
|
||||
import { resolveExecutableSql } from "@/lib/sqlExecutionTarget";
|
||||
import { isTauriRuntime } from "@/lib/tauriRuntime";
|
||||
import { isCloseTabShortcut, isExecuteSqlShortcut, isFocusSearchShortcut } from "@/lib/keyboardShortcuts";
|
||||
import {
|
||||
isCloseTabShortcut,
|
||||
isExecuteSqlShortcut,
|
||||
isFocusSearchShortcut,
|
||||
isSaveShortcut,
|
||||
} from "@/lib/keyboardShortcuts";
|
||||
import { isPreviewTab } from "@/lib/tabPresentation";
|
||||
import { supportsSqlFileExecution } from "@/lib/databaseCapabilities";
|
||||
import { classifyAiSqlExecution } from "@/lib/aiSqlExecutionPolicy";
|
||||
@@ -432,14 +437,7 @@ function handleKeydown(e: KeyboardEvent) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
activeTab.value?.mode === "query" &&
|
||||
!showSaveSqlDialog.value &&
|
||||
!e.isComposing &&
|
||||
!e.altKey &&
|
||||
(e.metaKey || e.ctrlKey) &&
|
||||
e.key.toLowerCase() === "s"
|
||||
) {
|
||||
if (activeTab.value?.mode === "query" && !showSaveSqlDialog.value && isSaveShortcut(e)) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void openSaveSqlDialog();
|
||||
@@ -669,6 +667,7 @@ onUnmounted(() => {
|
||||
@editor-selection-change="(v: string) => (selectedSql = v)"
|
||||
@editor-cursor-change="(p: number) => (cursorPos = p)"
|
||||
@format-error="toast(t('toolbar.formatSqlFailed'))"
|
||||
@save-sql="void openSaveSqlDialog()"
|
||||
@reload="
|
||||
(
|
||||
sql?: string,
|
||||
|
||||
@@ -28,6 +28,7 @@ const emit = defineEmits<{
|
||||
cursorChange: [pos: number];
|
||||
formatError: [message: string];
|
||||
execute: [sql: string];
|
||||
save: [];
|
||||
clickTable: [tableName: string];
|
||||
clickColumn: [columns: Array<{ name: string; table: string; schema?: string }>, error?: string | undefined];
|
||||
closeColumnPanel: [];
|
||||
@@ -319,6 +320,13 @@ onMounted(async () => {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "Mod-s",
|
||||
run: () => {
|
||||
emit("save");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const theme = await loadEditorTheme(ss.theme);
|
||||
|
||||
@@ -35,6 +35,7 @@ const emit = defineEmits<{
|
||||
"update:activeOutputView": [value: "result" | "explain" | "chart"];
|
||||
fixWithAi: [errorMessage: string];
|
||||
execute: [sqlOverride?: string];
|
||||
saveSql: [];
|
||||
cancel: [];
|
||||
explain: [];
|
||||
editorUpdate: [value: string];
|
||||
@@ -194,6 +195,7 @@ defineExpose({ focusSearch });
|
||||
@cursor-change="emit('editorCursorChange', $event)"
|
||||
@format-error="emit('formatError')"
|
||||
@execute="emit('execute')"
|
||||
@save="emit('saveSql')"
|
||||
@click-table="onHandleClickTable"
|
||||
@click-column="onHandleClickColumn"
|
||||
@close-column-panel="onHandleCloseColumnPanel"
|
||||
|
||||
@@ -648,7 +648,7 @@ watch(
|
||||
<div v-else-if="sourceError" class="flex flex-1 items-center justify-center px-4 text-sm text-destructive">
|
||||
{{ sourceError }}
|
||||
</div>
|
||||
<div v-else-if="sourceEditing" class="flex min-h-0 flex-1 flex-col">
|
||||
<div v-else-if="sourceEditing" class="flex min-h-0 flex-1 flex-col" data-object-source-editor>
|
||||
<QueryEditor
|
||||
v-model="sourceDraft"
|
||||
class="min-h-0 flex-1"
|
||||
@@ -657,7 +657,7 @@ watch(
|
||||
:dialect="sourceDialect"
|
||||
:format-dialect="sourceFormatDialect"
|
||||
force-word-wrap
|
||||
@execute="saveSource"
|
||||
@save="saveSource"
|
||||
/>
|
||||
<div v-if="sourceSaveError" class="shrink-0 border-t px-3 py-2 text-xs text-destructive">
|
||||
{{ sourceSaveError }}
|
||||
@@ -674,6 +674,7 @@ watch(
|
||||
:format-dialect="sourceFormatDialect"
|
||||
force-word-wrap
|
||||
read-only
|
||||
data-object-source-preview
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -26,6 +26,13 @@ export function isFocusSearchShortcut(event: ShortcutLikeEvent): boolean {
|
||||
return event.key.toLowerCase() === "f";
|
||||
}
|
||||
|
||||
export function isSaveShortcut(event: ShortcutLikeEvent): boolean {
|
||||
if (event.isComposing) return false;
|
||||
if (event.altKey) return false;
|
||||
if (!event.metaKey && !event.ctrlKey) return false;
|
||||
return event.key.toLowerCase() === "s";
|
||||
}
|
||||
|
||||
export function isCancelSearchShortcut(event: ShortcutLikeEvent): boolean {
|
||||
if (event.isComposing) return false;
|
||||
return event.key === "Escape";
|
||||
|
||||
Reference in New Issue
Block a user