1 parent
2b7264a531
commit
89aa315a2d
16 files changed
+360
-717
No files matched your search
@@ -276,6 +276,8 @@ const shortcutConflicts = computed(() =>
|
||||
return conflict ? [definition.id] : [];
|
||||
}),
|
||||
);
|
||||
const formatterEditorShortcutIds: ShortcutActionId[] = ["formatSql", "find", "replace", "saveSql", "acceptCompletion", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll"];
|
||||
const formatterEditorShortcutDefinitions = computed(() => formatterEditorShortcutIds.map((id) => SHORTCUT_DEFINITIONS.find((definition) => definition.id === id)).filter((definition): definition is (typeof SHORTCUT_DEFINITIONS)[number] => !!definition));
|
||||
const hasShortcutConflicts = computed(() => shortcutConflicts.value.length > 0);
|
||||
const shortcutsChanged = computed(() => JSON.stringify(editShortcuts.value) !== JSON.stringify(settingsStore.editorSettings.shortcuts));
|
||||
const hasBlockingShortcutConflicts = computed(() => shortcutsChanged.value && hasShortcutConflicts.value);
|
||||
@@ -1342,6 +1344,72 @@ watch(
|
||||
</section>
|
||||
|
||||
<section v-else-if="activeSettingsTab === 'formatter'" class="flex flex-col gap-5 py-2">
|
||||
<div class="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
||||
<div class="text-sm font-medium">{{ t("settings.sqlFormatterEditorShortcuts") }}</div>
|
||||
<div class="overflow-hidden rounded-md border border-border/70 bg-background">
|
||||
<div v-for="definition in formatterEditorShortcutDefinitions" :key="definition.id" class="group -mt-px grid gap-2 border-t border-border/70 px-3 py-2 transition-colors first:mt-0 first:border-t-0 hover:bg-muted/40 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center">
|
||||
<div class="min-w-0">
|
||||
<Label class="min-w-0 truncate leading-none">{{ t(definition.labelKey) }}</Label>
|
||||
</div>
|
||||
<div class="min-w-0 space-y-1">
|
||||
<div class="flex items-center justify-end gap-1.5">
|
||||
<input
|
||||
:data-shortcut-input="definition.id"
|
||||
:value="editingShortcutId === definition.id ? '' : formatShortcutPill(editShortcuts[definition.id])"
|
||||
:style="{
|
||||
width: editingShortcutId === definition.id ? shortcutPressShortcutInputWidth : `${Math.max(4, formatShortcutPill(editShortcuts[definition.id]).length + 3)}ch`,
|
||||
}"
|
||||
readonly
|
||||
:aria-invalid="shortcutConflicts.includes(definition.id)"
|
||||
:placeholder="t('settings.shortcutPressShortcut')"
|
||||
class="h-7 w-auto min-w-12 max-w-32 shrink-0 cursor-default rounded-full border border-transparent bg-background px-2.5 text-center font-mono text-[13px] font-semibold text-foreground/75 shadow-inner outline-none selection:bg-transparent placeholder:text-muted-foreground aria-invalid:border-destructive/70 aria-invalid:text-destructive aria-invalid:ring-destructive/20"
|
||||
:class="editingShortcutId === definition.id ? 'max-w-44 cursor-text border-border/80 bg-background text-left text-foreground shadow-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/35' : ''"
|
||||
@keydown="(event: KeyboardEvent) => onShortcutKeydown(definition.id, event)"
|
||||
/>
|
||||
<Button
|
||||
v-if="editingShortcutId !== definition.id"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="h-7 w-7 shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"
|
||||
:aria-label="t('settings.shortcutPressShortcut')"
|
||||
@click="focusShortcutInput(definition.id)"
|
||||
>
|
||||
<Pencil class="h-4 w-4" />
|
||||
</Button>
|
||||
<Button v-else type="button" variant="ghost" size="sm" class="h-7 shrink-0 px-2 text-sm font-medium text-muted-foreground hover:text-foreground" @click="cancelShortcutEdit">
|
||||
{{ t("settings.cancel") }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="editingShortcutId !== definition.id"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="h-7 w-7 shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"
|
||||
:aria-label="t('settings.reset')"
|
||||
@click="resetShortcut(definition.id)"
|
||||
>
|
||||
<RotateCcw class="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
v-if="editingShortcutId !== definition.id && editShortcuts[definition.id]"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="h-7 w-7 shrink-0 text-muted-foreground opacity-0 transition-opacity hover:text-destructive focus-visible:opacity-100 group-hover:opacity-100"
|
||||
:aria-label="t('settings.shortcutClear')"
|
||||
@click="clearShortcut(definition.id)"
|
||||
>
|
||||
<X class="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<p v-if="shortcutConflicts.includes(definition.id)" class="text-xs text-destructive">
|
||||
{{ t("settings.shortcutConflict") }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<SqlFormatterSettingsPanel v-model="editSqlFormatter" @validity-change="(value: boolean) => (sqlFormatterConfigValid = value)" />
|
||||
</section>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import {
|
||||
} from "@/lib/queryEditorTableDrop";
|
||||
import { EDITOR_FONT_FAMILY_CSS_VAR, EDITOR_FONT_SIZE_CSS_VAR, loadEditorTheme, editorFontTheme, sqlCompletionTheme } from "@/lib/editorThemes";
|
||||
import { clampEditorFontSize, createEditorZoomCommitScheduler, fontSizeFromGestureScale, fontSizeFromWheelDelta } from "@/lib/editorZoom";
|
||||
import { shortcutToCodeMirrorKey } from "@/lib/shortcutRegistry";
|
||||
import { normalizeShortcutSettings, shortcutToCodeMirrorKey } from "@/lib/shortcutRegistry";
|
||||
import { trimmedSelectionLayer } from "@/lib/codemirrorTrimmedSelectionLayer";
|
||||
import { selectionMatchOccurrences } from "@/lib/codemirrorSelectionMatches";
|
||||
import { isSchemaAware, isSingleDatabase } from "@/lib/databaseFeatureSupport";
|
||||
@@ -165,6 +165,15 @@ let codeMirrorCompletionStatus: typeof import("@codemirror/autocomplete").comple
|
||||
let codeMirrorAcceptCompletion: typeof import("@codemirror/autocomplete").acceptCompletion | null = null;
|
||||
let codeMirrorStartCompletion: typeof import("@codemirror/autocomplete").startCompletion | null = null;
|
||||
let codeMirrorIndentMore: typeof import("@codemirror/commands").indentMore | null = null;
|
||||
let codeMirrorIndentLess: typeof import("@codemirror/commands").indentLess | null = null;
|
||||
let codeMirrorCopyLineDown: typeof import("@codemirror/commands").copyLineDown | null = null;
|
||||
let codeMirrorCopyLineUp: typeof import("@codemirror/commands").copyLineUp | null = null;
|
||||
let codeMirrorDeleteLine: typeof import("@codemirror/commands").deleteLine | null = null;
|
||||
let codeMirrorMoveLineUp: typeof import("@codemirror/commands").moveLineUp | null = null;
|
||||
let codeMirrorMoveLineDown: typeof import("@codemirror/commands").moveLineDown | null = null;
|
||||
let codeMirrorUndo: typeof import("@codemirror/commands").undo | null = null;
|
||||
let codeMirrorRedo: typeof import("@codemirror/commands").redo | null = null;
|
||||
let codeMirrorSelectAll: typeof import("@codemirror/commands").selectAll | null = null;
|
||||
let codeMirrorInsertNewlineKeepIndent: typeof import("@codemirror/commands").insertNewlineKeepIndent | null = null;
|
||||
let setSqlDiagnosticsEffect: import("@codemirror/state").StateEffectType<SqlSemanticDiagnostic[]> | null = null;
|
||||
let semanticDiagnostics: SqlSemanticDiagnostic[] = [];
|
||||
@@ -340,8 +349,9 @@ const contextMenuItems = computed<ContextMenuItem[]>(() => [
|
||||
]);
|
||||
|
||||
function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view"))["keymap"]) {
|
||||
const shortcuts = settingsStore.editorSettings.shortcuts;
|
||||
const shortcuts = normalizeShortcutSettings(settingsStore.editorSettings.shortcuts);
|
||||
const Prec = codeMirrorPrec;
|
||||
const binding = (shortcut: string, run: (view: EditorViewType) => boolean) => (shortcut ? [{ key: shortcutToCodeMirrorKey(shortcut), preventDefault: true, run }] : []);
|
||||
return [
|
||||
Prec?.high(
|
||||
codeMirrorKeymap.of([
|
||||
@@ -350,37 +360,36 @@ function runKeymapExtension(codeMirrorKeymap: (typeof import("@codemirror/view")
|
||||
run: codeMirrorInsertNewlineKeepIndent ?? undefined,
|
||||
shift: codeMirrorInsertNewlineKeepIndent ?? undefined,
|
||||
},
|
||||
{
|
||||
key: shortcutToCodeMirrorKey(shortcuts.find),
|
||||
preventDefault: true,
|
||||
run: openSearch,
|
||||
},
|
||||
{
|
||||
key: shortcutToCodeMirrorKey(shortcuts.replace),
|
||||
preventDefault: true,
|
||||
run: openReplace,
|
||||
},
|
||||
{
|
||||
key: shortcutToCodeMirrorKey(shortcuts.executeSql),
|
||||
preventDefault: true,
|
||||
run: executeCurrentSql,
|
||||
},
|
||||
{
|
||||
key: shortcutToCodeMirrorKey(shortcuts.saveSql),
|
||||
preventDefault: true,
|
||||
run: () => {
|
||||
emit("save");
|
||||
return true;
|
||||
},
|
||||
},
|
||||
...binding(shortcuts.find, openSearch),
|
||||
...binding(shortcuts.replace, openReplace),
|
||||
...binding(shortcuts.executeSql, executeCurrentSql),
|
||||
...binding(shortcuts.saveSql, () => {
|
||||
emit("save");
|
||||
return true;
|
||||
}),
|
||||
...binding(shortcuts.formatSql, () => {
|
||||
void formatCurrentSql();
|
||||
return true;
|
||||
}),
|
||||
...binding(shortcuts.indentMore, (view) => codeMirrorIndentMore?.(view) ?? false),
|
||||
...binding(shortcuts.indentLess, (view) => codeMirrorIndentLess?.(view) ?? false),
|
||||
...binding(shortcuts.duplicateLine, (view) => codeMirrorCopyLineDown?.(view) ?? false),
|
||||
...binding(shortcuts.deleteLine, (view) => codeMirrorDeleteLine?.(view) ?? false),
|
||||
...binding(shortcuts.moveLineUp, (view) => codeMirrorMoveLineUp?.(view) ?? false),
|
||||
...binding(shortcuts.moveLineDown, (view) => codeMirrorMoveLineDown?.(view) ?? false),
|
||||
...binding(shortcuts.copyLineUp, (view) => codeMirrorCopyLineUp?.(view) ?? false),
|
||||
...binding(shortcuts.copyLineDown, (view) => codeMirrorCopyLineDown?.(view) ?? false),
|
||||
...binding(shortcuts.undo, (view) => codeMirrorUndo?.(view) ?? false),
|
||||
...binding(shortcuts.redo, (view) => codeMirrorRedo?.(view) ?? false),
|
||||
...binding(shortcuts.selectAll, (view) => codeMirrorSelectAll?.(view) ?? false),
|
||||
]),
|
||||
) ?? [],
|
||||
codeMirrorKeymap.of([
|
||||
{
|
||||
key: shortcutToCodeMirrorKey(shortcuts.acceptCompletion),
|
||||
run: (view) => codeMirrorAcceptCompletion?.(view) ?? false,
|
||||
},
|
||||
]),
|
||||
codeMirrorKeymap.of(
|
||||
binding(shortcuts.acceptCompletion, (view) => codeMirrorAcceptCompletion?.(view) ?? false).map((item) => ({
|
||||
...item,
|
||||
preventDefault: false,
|
||||
})),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -719,6 +728,7 @@ function scheduleSemanticDiagnostics(delay = 500) {
|
||||
}
|
||||
|
||||
async function formatCurrentSql() {
|
||||
if (props.readOnly) return;
|
||||
const currentView = view.value;
|
||||
if (!currentView) return;
|
||||
|
||||
@@ -1342,7 +1352,7 @@ onMounted(async () => {
|
||||
{ EditorState, Compartment, Prec, StateEffect, StateField },
|
||||
{ sql, MSSQL, MySQL, PostgreSQL, SQLDialect },
|
||||
{ autocompletion, startCompletion, acceptCompletion, closeBrackets, closeBracketsKeymap, snippetCompletion, completionStatus, completionKeymap },
|
||||
{ indentMore, insertNewlineKeepIndent, history, defaultKeymap, historyKeymap },
|
||||
{ copyLineDown, copyLineUp, deleteLine, indentLess, indentMore, insertNewlineKeepIndent, moveLineDown, moveLineUp, redo, selectAll, undo, history, defaultKeymap, historyKeymap },
|
||||
{ bracketMatching, foldGutter, indentOnInput, syntaxHighlighting, defaultHighlightStyle, foldKeymap },
|
||||
{ searchKeymap },
|
||||
] = await Promise.all([import("@codemirror/view"), import("@codemirror/state"), import("@codemirror/lang-sql"), import("@codemirror/autocomplete"), import("@codemirror/commands"), import("@codemirror/language"), import("@codemirror/search")]);
|
||||
@@ -1361,6 +1371,15 @@ onMounted(async () => {
|
||||
codeMirrorAcceptCompletion = acceptCompletion;
|
||||
codeMirrorStartCompletion = startCompletion;
|
||||
codeMirrorIndentMore = indentMore;
|
||||
codeMirrorIndentLess = indentLess;
|
||||
codeMirrorCopyLineDown = copyLineDown;
|
||||
codeMirrorCopyLineUp = copyLineUp;
|
||||
codeMirrorDeleteLine = deleteLine;
|
||||
codeMirrorMoveLineUp = moveLineUp;
|
||||
codeMirrorMoveLineDown = moveLineDown;
|
||||
codeMirrorUndo = undo;
|
||||
codeMirrorRedo = redo;
|
||||
codeMirrorSelectAll = selectAll;
|
||||
codeMirrorInsertNewlineKeepIndent = insertNewlineKeepIndent;
|
||||
|
||||
const diagnosticTheme = EditorView.baseTheme({
|
||||
|
||||
@@ -3,7 +3,6 @@ import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { Upload, Download, RotateCcw, WandSparkles, Save, Copy } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
@@ -14,27 +13,20 @@ import {
|
||||
DEFAULT_SQL_FORMATTER_SETTINGS,
|
||||
SQL_FORMATTER_CONFIG_FORMATTER,
|
||||
SQL_FORMATTER_CONFIG_VERSION,
|
||||
normalizeSqlFormatterEditorSettings,
|
||||
normalizeSqlFormatterSettings,
|
||||
parseSqlFormatterConfig,
|
||||
serializeSqlFormatterConfig,
|
||||
sqlFormatterPlatformFromNavigator,
|
||||
syncSqlFormatterConfigDraft,
|
||||
validateSqlFormatterEditorSettings,
|
||||
type SqlFormatterCase,
|
||||
type SqlFormatterEditorShortcut,
|
||||
type SqlFormatterEditorShortcutId,
|
||||
type SqlFormatterExpressionWidth,
|
||||
type SqlFormatterIndentStyle,
|
||||
type SqlFormatterLinesBetweenQueries,
|
||||
type SqlFormatterLogicalOperatorNewline,
|
||||
type SqlFormatterOptionSettings,
|
||||
type SqlFormatterParamTypes,
|
||||
type SqlFormatterPlatform,
|
||||
type SqlFormatterSettings,
|
||||
type SqlFormatterTabWidth,
|
||||
} from "@/lib/sqlFormatterConfig";
|
||||
import { createSqlFormatterConfigKeymap, sqlFormatterConfigShortcutLabelKey, sqlFormatterConfigShortcutRows } from "@/lib/sqlFormatterConfigEditor";
|
||||
|
||||
type EditorViewInstance = import("@codemirror/view").EditorView;
|
||||
type CodeMirrorModules = {
|
||||
@@ -64,7 +56,6 @@ const jsonDraft = ref(serializeSqlFormatterConfig(props.modelValue));
|
||||
const jsonValidationMessage = ref("");
|
||||
const importError = ref("");
|
||||
const advancedConfigError = ref("");
|
||||
const editorShortcutError = ref("");
|
||||
const jsonEditorLoading = ref(false);
|
||||
const jsonEditorReady = ref(false);
|
||||
const jsonEditorLoadError = ref("");
|
||||
@@ -73,11 +64,9 @@ const focusedAdvancedOption = ref<"paramTypes" | null>(null);
|
||||
|
||||
let cmView: EditorViewInstance | null = null;
|
||||
let cmModules: CodeMirrorModules | null = null;
|
||||
let keymapCompartment: import("@codemirror/state").Compartment | null = null;
|
||||
let lastValidity: boolean | null = null;
|
||||
|
||||
const settings = computed(() => normalizeSqlFormatterSettings(props.modelValue));
|
||||
const shortcutRows = computed(() => sqlFormatterConfigShortcutRows(globalThis.navigator?.platform || "", settings.value.editor));
|
||||
|
||||
const caseOptions: { value: SqlFormatterCase; labelKey: string }[] = [
|
||||
{ value: "upper", labelKey: "settings.sqlFormatterCaseUpper" },
|
||||
@@ -96,14 +85,6 @@ const indentStyleOptions: { value: SqlFormatterIndentStyle; labelKey: string }[]
|
||||
{ value: "tabularRight", labelKey: "settings.sqlFormatterIndentStyleTabularRight" },
|
||||
];
|
||||
|
||||
const shortcutPlatformOptions: { value: SqlFormatterPlatform; labelKey: string }[] = [
|
||||
{ value: "windows", labelKey: "settings.sqlFormatterShortcutWindows" },
|
||||
{ value: "linux", labelKey: "settings.sqlFormatterShortcutLinux" },
|
||||
{ value: "macos", labelKey: "settings.sqlFormatterShortcutMacos" },
|
||||
];
|
||||
const currentShortcutPlatform = computed(() => sqlFormatterPlatformFromNavigator(globalThis.navigator?.platform || ""));
|
||||
const currentShortcutPlatformOption = computed(() => shortcutPlatformOptions.find((option) => option.value === currentShortcutPlatform.value) ?? shortcutPlatformOptions[0]);
|
||||
|
||||
const tabWidthOptions: SqlFormatterTabWidth[] = [2, 4];
|
||||
const expressionWidthOptions: SqlFormatterExpressionWidth[] = [50, 80, 120];
|
||||
const linesBetweenQueriesOptions: SqlFormatterLinesBetweenQueries[] = [0, 1, 2];
|
||||
@@ -129,11 +110,6 @@ const sqlFormatterConfigErrorKeys: Record<string, string> = {
|
||||
"Unsupported formatter.": "settings.sqlFormatterConfigErrorFormatter",
|
||||
"Unsupported formatter option: params.": "settings.sqlFormatterConfigErrorUnsupportedParams",
|
||||
"Config options must be a JSON object.": "settings.sqlFormatterConfigErrorOptionsObject",
|
||||
"Config editor must be a JSON object.": "settings.sqlFormatterConfigErrorEditorObject",
|
||||
"Unsupported editor scope.": "settings.sqlFormatterConfigErrorEditorScope",
|
||||
"Invalid editor platforms.": "settings.sqlFormatterConfigErrorEditorPlatforms",
|
||||
"Config editor shortcuts must be an array.": "settings.sqlFormatterConfigErrorEditorShortcutsArray",
|
||||
"Invalid editor shortcut value.": "settings.sqlFormatterConfigErrorEditorShortcutValue",
|
||||
};
|
||||
|
||||
function emitValidity(value: boolean) {
|
||||
@@ -167,21 +143,6 @@ function localizeSqlFormatterConfigError(message: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
const unknownShortcut = message.match(/^Unknown editor shortcut: (.+)\.$/);
|
||||
if (unknownShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorUnknownEditorShortcut", { shortcut: unknownShortcut[1] });
|
||||
}
|
||||
|
||||
const invalidShortcut = message.match(/^Invalid editor shortcut value: (.+)\.$/);
|
||||
if (invalidShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorInvalidEditorShortcut", { shortcut: invalidShortcut[1] });
|
||||
}
|
||||
|
||||
const duplicateShortcut = message.match(/^Duplicate editor shortcut: (.+)\.$/);
|
||||
if (duplicateShortcut?.[1]) {
|
||||
return t("settings.sqlFormatterConfigErrorDuplicateEditorShortcut", { shortcut: duplicateShortcut[1] });
|
||||
}
|
||||
|
||||
return t("settings.sqlFormatterConfigErrorInvalidConfig");
|
||||
}
|
||||
|
||||
@@ -206,13 +167,6 @@ function updateSettings(next: unknown) {
|
||||
emit("update:modelValue", normalizeSqlFormatterSettings(next));
|
||||
}
|
||||
|
||||
function validateEditorShortcuts(value = settings.value.editor): boolean {
|
||||
const result = validateSqlFormatterEditorSettings(value);
|
||||
editorShortcutError.value = result.ok ? "" : localizeSqlFormatterConfigError(result.message);
|
||||
emitValidity(activeMode.value === "form" ? result.ok : !jsonValidationMessage.value);
|
||||
return result.ok;
|
||||
}
|
||||
|
||||
function updateOption<K extends keyof SqlFormatterSettings>(key: K, value: SqlFormatterSettings[K]) {
|
||||
updateSettings({ ...settings.value, [key]: value });
|
||||
}
|
||||
@@ -308,37 +262,6 @@ function applyAdvancedJsonOption() {
|
||||
advancedConfigError.value = "";
|
||||
}
|
||||
|
||||
function updateEditorShortcut(id: SqlFormatterEditorShortcutId, updater: (shortcut: SqlFormatterEditorShortcut) => SqlFormatterEditorShortcut) {
|
||||
const editor = normalizeSqlFormatterEditorSettings(settings.value.editor);
|
||||
const next = {
|
||||
...settings.value,
|
||||
editor: {
|
||||
...editor,
|
||||
shortcuts: editor.shortcuts.map((shortcut) => (shortcut.id === id ? updater({ ...shortcut, keys: { ...shortcut.keys } }) : shortcut)),
|
||||
},
|
||||
};
|
||||
updateSettings(next);
|
||||
validateEditorShortcuts(next.editor);
|
||||
}
|
||||
|
||||
function updateEditorShortcutEnabled(id: SqlFormatterEditorShortcutId, enabled: boolean) {
|
||||
updateEditorShortcut(id, (shortcut) => ({ ...shortcut, enabled }));
|
||||
}
|
||||
|
||||
function updateEditorShortcutKey(id: SqlFormatterEditorShortcutId, platform: SqlFormatterPlatform, value: string) {
|
||||
updateEditorShortcut(id, (shortcut) => ({
|
||||
...shortcut,
|
||||
keys: {
|
||||
...shortcut.keys,
|
||||
[platform]: value,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
function shortcutLabelKey(id: SqlFormatterEditorShortcutId): string {
|
||||
return sqlFormatterConfigShortcutLabelKey(id);
|
||||
}
|
||||
|
||||
function importConfig() {
|
||||
importError.value = "";
|
||||
fileInputRef.value?.click();
|
||||
@@ -425,7 +348,6 @@ async function loadCodeMirrorModules(): Promise<CodeMirrorModules> {
|
||||
function destroyJsonEditor() {
|
||||
cmView?.destroy();
|
||||
cmView = null;
|
||||
keymapCompartment = null;
|
||||
jsonEditorReady.value = false;
|
||||
jsonEditorLoadError.value = "";
|
||||
}
|
||||
@@ -434,34 +356,7 @@ function jsonEditorKeymapExtension(modules: CodeMirrorModules) {
|
||||
const { keymap } = modules.view;
|
||||
const commands = modules.commands;
|
||||
const search = modules.search;
|
||||
const customKeymap = createSqlFormatterConfigKeymap(
|
||||
{
|
||||
indentMore: commands.indentMore,
|
||||
indentLess: commands.indentLess,
|
||||
copyLineDown: commands.copyLineDown,
|
||||
copyLineUp: commands.copyLineUp,
|
||||
deleteLine: commands.deleteLine,
|
||||
moveLineUp: commands.moveLineUp,
|
||||
moveLineDown: commands.moveLineDown,
|
||||
undo: commands.undo,
|
||||
redo: commands.redo,
|
||||
selectAll: commands.selectAll,
|
||||
openSearchPanel: search.openSearchPanel,
|
||||
},
|
||||
{
|
||||
apply: applyJsonDraft,
|
||||
formatJson: formatJsonDraft,
|
||||
},
|
||||
settings.value.editor,
|
||||
);
|
||||
return keymap.of([...customKeymap, ...search.searchKeymap, ...commands.historyKeymap, ...commands.defaultKeymap]);
|
||||
}
|
||||
|
||||
function reconfigureJsonEditorKeymap() {
|
||||
if (!cmView || !cmModules || !keymapCompartment) return;
|
||||
cmView.dispatch({
|
||||
effects: keymapCompartment.reconfigure(jsonEditorKeymapExtension(cmModules)),
|
||||
});
|
||||
return keymap.of([...search.searchKeymap, ...commands.historyKeymap, ...commands.defaultKeymap]);
|
||||
}
|
||||
|
||||
async function initJsonEditor() {
|
||||
@@ -473,11 +368,10 @@ async function initJsonEditor() {
|
||||
if (activeMode.value !== "json" || cmView || !jsonEditorRef.value) return;
|
||||
|
||||
const { EditorView, lineNumbers, highlightActiveLine, highlightActiveLineGutter } = modules.view;
|
||||
const { EditorState, Compartment } = modules.state;
|
||||
const { EditorState } = modules.state;
|
||||
const { json } = modules.langJson;
|
||||
const commands = modules.commands;
|
||||
const search = modules.search;
|
||||
keymapCompartment = new Compartment();
|
||||
|
||||
const state = EditorState.create({
|
||||
doc: jsonDraft.value,
|
||||
@@ -488,7 +382,7 @@ async function initJsonEditor() {
|
||||
commands.history(),
|
||||
search.search({ top: true }),
|
||||
json(),
|
||||
keymapCompartment.of(jsonEditorKeymapExtension(modules)),
|
||||
jsonEditorKeymapExtension(modules),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (!update.docChanged) return;
|
||||
@@ -542,15 +436,6 @@ watch(
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => settings.value.editor,
|
||||
(value) => {
|
||||
validateEditorShortcuts(value);
|
||||
if (activeMode.value === "json") reconfigureJsonEditorKeymap();
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
@@ -578,7 +463,6 @@ watch(
|
||||
await initJsonEditor();
|
||||
return;
|
||||
}
|
||||
validateEditorShortcuts();
|
||||
destroyJsonEditor();
|
||||
},
|
||||
{ immediate: true },
|
||||
@@ -794,27 +678,6 @@ onBeforeUnmount(() => {
|
||||
{{ advancedConfigError }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 rounded-md border border-border/70 bg-muted/10 p-3">
|
||||
<div class="text-sm font-medium">{{ t("settings.sqlFormatterEditorShortcuts") }}</div>
|
||||
<div class="overflow-x-auto rounded-md border bg-background">
|
||||
<div class="grid min-w-[420px] grid-cols-[minmax(10rem,1fr)_5rem_minmax(12rem,1.2fr)] items-center gap-2 border-b bg-muted/30 px-3 py-2 text-xs font-medium text-muted-foreground">
|
||||
<span>{{ t("settings.sqlFormatterShortcutAction") }}</span>
|
||||
<span class="text-center">{{ t("settings.sqlFormatterShortcutEnabled") }}</span>
|
||||
<span>{{ t(currentShortcutPlatformOption.labelKey) }}</span>
|
||||
</div>
|
||||
<div v-for="shortcut in settings.editor.shortcuts" :key="shortcut.id" class="grid min-w-[420px] grid-cols-[minmax(10rem,1fr)_5rem_minmax(12rem,1.2fr)] items-center gap-2 border-b px-3 py-2 text-xs last:border-b-0">
|
||||
<span class="min-w-0 truncate text-muted-foreground">{{ t(shortcutLabelKey(shortcut.id)) }}</span>
|
||||
<div class="flex justify-center">
|
||||
<Switch :model-value="shortcut.enabled" @update:model-value="(value: boolean) => updateEditorShortcutEnabled(shortcut.id, value)" />
|
||||
</div>
|
||||
<Input :model-value="shortcut.keys[currentShortcutPlatform]" class="h-8 font-mono text-xs" :disabled="!shortcut.enabled" @update:model-value="(value: string | number) => updateEditorShortcutKey(shortcut.id, currentShortcutPlatform, String(value))" />
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="editorShortcutError" class="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{{ editorShortcutError }}
|
||||
</p>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="json" class="m-0 flex min-h-0 flex-col gap-3 pt-2">
|
||||
@@ -851,15 +714,6 @@ onBeforeUnmount(() => {
|
||||
<p v-if="jsonValidationMessage" class="rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
|
||||
{{ jsonValidationMessage }}
|
||||
</p>
|
||||
|
||||
<div class="grid gap-1 rounded-md border border-border/70 bg-muted/20 p-2 sm:grid-cols-2">
|
||||
<div v-for="row in shortcutRows" :key="row.id" class="flex min-w-0 items-center justify-between gap-2 rounded px-1.5 py-1 text-xs">
|
||||
<span class="truncate text-muted-foreground">{{ t(row.labelKey) }}</span>
|
||||
<span class="shrink-0 rounded border bg-background px-1.5 py-0.5 font-mono text-[11px]">
|
||||
{{ row.shortcut }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user