diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue index 52cc13b4cd..ae809fc268 100644 --- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue +++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue @@ -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(
+
+
{{ t("settings.sqlFormatterEditorShortcuts") }}
+
+
+
+ +
+
+
+ + + + + +
+

+ {{ t("settings.shortcutConflict") }} +

+
+
+
+
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue index 11f889b8a4..f06e332cd3 100644 --- a/apps/desktop/src/components/editor/QueryEditor.vue +++ b/apps/desktop/src/components/editor/QueryEditor.vue @@ -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 | null = null; let semanticDiagnostics: SqlSemanticDiagnostic[] = []; @@ -340,8 +349,9 @@ const contextMenuItems = computed(() => [ ]); 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({ diff --git a/apps/desktop/src/components/editor/SqlFormatterSettingsPanel.vue b/apps/desktop/src/components/editor/SqlFormatterSettingsPanel.vue index 2f257f2941..f9c62f2b58 100644 --- a/apps/desktop/src/components/editor/SqlFormatterSettingsPanel.vue +++ b/apps/desktop/src/components/editor/SqlFormatterSettingsPanel.vue @@ -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 = { "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(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 { 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 }}

- -
-
{{ t("settings.sqlFormatterEditorShortcuts") }}
-
-
- {{ t("settings.sqlFormatterShortcutAction") }} - {{ t("settings.sqlFormatterShortcutEnabled") }} - {{ t(currentShortcutPlatformOption.labelKey) }} -
-
- {{ t(shortcutLabelKey(shortcut.id)) }} -
- -
- -
-
-

- {{ editorShortcutError }} -

-
@@ -851,15 +714,6 @@ onBeforeUnmount(() => {

{{ jsonValidationMessage }}

- -
-
- {{ t(row.labelKey) }} - - {{ row.shortcut }} - -
-
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 207048fce2..dcdd49af24 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -1769,7 +1769,7 @@ sqlFormatterAdvancedOptions: "Advanced options", sqlFormatterParams: "Params", sqlFormatterParamTypes: "Param types", - sqlFormatterEditorShortcuts: "JSON editor shortcuts", + sqlFormatterEditorShortcuts: "Shortcuts", sqlFormatterShortcutAction: "Action", sqlFormatterShortcutEnabled: "Enabled", sqlFormatterShortcutWindows: "Windows", @@ -1952,6 +1952,18 @@ shortcutReplace: "Replace", shortcutSaveSql: "Save SQL", shortcutAcceptCompletion: "Accept completion", + shortcutFormatSql: "Format SQL", + shortcutIndentMore: "Indent more", + shortcutIndentLess: "Indent less", + shortcutDuplicateLine: "Duplicate current line", + shortcutDeleteLine: "Delete current line", + shortcutMoveLineUp: "Move line up", + shortcutMoveLineDown: "Move line down", + shortcutCopyLineUp: "Copy line up", + shortcutCopyLineDown: "Copy line down", + shortcutUndo: "Undo", + shortcutRedo: "Redo", + shortcutSelectAll: "Select all", shortcutCopyCurrentRow: "Copy current data row", shortcutDeleteCurrentRow: "Delete current data row", shortcutNewQuery: "New query", diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index bf1c55a339..0bfc4164cd 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -1548,7 +1548,7 @@ sqlFormatterAdvancedOptions: "Opciones avanzadas", sqlFormatterParams: "Parámetros", sqlFormatterParamTypes: "Tipos de parámetro", - sqlFormatterEditorShortcuts: "Atajos del editor JSON", + sqlFormatterEditorShortcuts: "Atajos", sqlFormatterShortcutAction: "Acción", sqlFormatterShortcutEnabled: "Activo", sqlFormatterShortcutWindows: "Windows", @@ -1728,6 +1728,18 @@ shortcutReplace: "Reemplazar", shortcutSaveSql: "Guardar SQL", shortcutAcceptCompletion: "Aceptar completado", + shortcutFormatSql: "Formatear SQL", + shortcutIndentMore: "Aumentar sangría", + shortcutIndentLess: "Reducir sangría", + shortcutDuplicateLine: "Duplicar línea actual", + shortcutDeleteLine: "Eliminar línea actual", + shortcutMoveLineUp: "Mover línea arriba", + shortcutMoveLineDown: "Mover línea abajo", + shortcutCopyLineUp: "Copiar línea arriba", + shortcutCopyLineDown: "Copiar línea abajo", + shortcutUndo: "Deshacer", + shortcutRedo: "Rehacer", + shortcutSelectAll: "Seleccionar todo", shortcutCopyCurrentRow: "Copiar fila de datos actual", shortcutDeleteCurrentRow: "Eliminar fila de datos actual", shortcutNewQuery: "Nueva consulta", diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index 6edfa27db6..355437a182 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -1665,7 +1665,7 @@ sqlFormatterAdvancedOptions: "Opzioni avanzate", sqlFormatterParams: "Parametri", sqlFormatterParamTypes: "Tipi parametro", - sqlFormatterEditorShortcuts: "Scorciatoie editor JSON", + sqlFormatterEditorShortcuts: "Scorciatoie", sqlFormatterShortcutAction: "Azione", sqlFormatterShortcutEnabled: "Attiva", sqlFormatterShortcutWindows: "Windows", @@ -1848,6 +1848,18 @@ shortcutReplace: "Sostituisci", shortcutSaveSql: "Salva SQL", shortcutAcceptCompletion: "Accetta completamento", + shortcutFormatSql: "Formatta SQL", + shortcutIndentMore: "Aumenta rientro", + shortcutIndentLess: "Riduci rientro", + shortcutDuplicateLine: "Duplica riga corrente", + shortcutDeleteLine: "Elimina riga corrente", + shortcutMoveLineUp: "Sposta riga su", + shortcutMoveLineDown: "Sposta riga giù", + shortcutCopyLineUp: "Copia riga su", + shortcutCopyLineDown: "Copia riga giù", + shortcutUndo: "Annulla", + shortcutRedo: "Ripeti", + shortcutSelectAll: "Seleziona tutto", shortcutCopyCurrentRow: "Copia riga dati corrente", shortcutDeleteCurrentRow: "Elimina riga dati corrente", shortcutNewQuery: "Nuova query", diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index 530d9abb5f..2f1883a601 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -1665,7 +1665,7 @@ sqlFormatterAdvancedOptions: "Opções avançadas", sqlFormatterParams: "Parâmetros", sqlFormatterParamTypes: "Tipos de parâmetro", - sqlFormatterEditorShortcuts: "Atalhos do editor JSON", + sqlFormatterEditorShortcuts: "Atalhos", sqlFormatterShortcutAction: "Ação", sqlFormatterShortcutEnabled: "Ativo", sqlFormatterShortcutWindows: "Windows", @@ -1848,6 +1848,18 @@ shortcutReplace: "Substituir", shortcutSaveSql: "Salvar SQL", shortcutAcceptCompletion: "Aceitar autocompletar", + shortcutFormatSql: "Formatar SQL", + shortcutIndentMore: "Aumentar recuo", + shortcutIndentLess: "Reduzir recuo", + shortcutDuplicateLine: "Duplicar linha atual", + shortcutDeleteLine: "Excluir linha atual", + shortcutMoveLineUp: "Mover linha para cima", + shortcutMoveLineDown: "Mover linha para baixo", + shortcutCopyLineUp: "Copiar linha para cima", + shortcutCopyLineDown: "Copiar linha para baixo", + shortcutUndo: "Desfazer", + shortcutRedo: "Refazer", + shortcutSelectAll: "Selecionar tudo", shortcutCopyCurrentRow: "Copiar linha de dados atual", shortcutDeleteCurrentRow: "Excluir linha de dados atual", shortcutNewQuery: "Nova consulta", diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index 86e35003b2..60a4ad0f1c 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -1768,7 +1768,7 @@ sqlFormatterAdvancedOptions: "高级选项", sqlFormatterParams: "参数替换", sqlFormatterParamTypes: "参数类型", - sqlFormatterEditorShortcuts: "JSON 编辑器快捷键", + sqlFormatterEditorShortcuts: "快捷键", sqlFormatterShortcutAction: "功能", sqlFormatterShortcutEnabled: "启用", sqlFormatterShortcutWindows: "Windows", @@ -1951,6 +1951,18 @@ shortcutReplace: "替换", shortcutSaveSql: "保存 SQL", shortcutAcceptCompletion: "接受补全", + shortcutFormatSql: "格式化 SQL", + shortcutIndentMore: "增加缩进", + shortcutIndentLess: "减少缩进", + shortcutDuplicateLine: "复制当前行", + shortcutDeleteLine: "删除当前行", + shortcutMoveLineUp: "上移当前行", + shortcutMoveLineDown: "下移当前行", + shortcutCopyLineUp: "向上复制当前行", + shortcutCopyLineDown: "向下复制当前行", + shortcutUndo: "撤销", + shortcutRedo: "重做", + shortcutSelectAll: "全选", shortcutCopyCurrentRow: "复制当前数据行", shortcutDeleteCurrentRow: "删除当前数据行", shortcutNewQuery: "新建查询", diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts index 776dbf1060..f50f784110 100644 --- a/apps/desktop/src/i18n/locales/zh-TW.ts +++ b/apps/desktop/src/i18n/locales/zh-TW.ts @@ -1642,7 +1642,7 @@ sqlFormatterAdvancedOptions: "進階選項", sqlFormatterParams: "參數替換", sqlFormatterParamTypes: "參數類型", - sqlFormatterEditorShortcuts: "JSON 編輯器快速鍵", + sqlFormatterEditorShortcuts: "快速鍵", sqlFormatterShortcutAction: "功能", sqlFormatterShortcutEnabled: "啟用", sqlFormatterShortcutWindows: "Windows", @@ -1820,6 +1820,18 @@ shortcutReplace: "取代", shortcutSaveSql: "儲存 SQL", shortcutAcceptCompletion: "接受補全", + shortcutFormatSql: "格式化 SQL", + shortcutIndentMore: "增加縮排", + shortcutIndentLess: "減少縮排", + shortcutDuplicateLine: "複製目前行", + shortcutDeleteLine: "刪除目前行", + shortcutMoveLineUp: "上移目前行", + shortcutMoveLineDown: "下移目前行", + shortcutCopyLineUp: "向上複製目前行", + shortcutCopyLineDown: "向下複製目前行", + shortcutUndo: "復原", + shortcutRedo: "重做", + shortcutSelectAll: "全選", shortcutCopyCurrentRow: "複製目前資料列", shortcutDeleteCurrentRow: "刪除目前資料列", shortcutNewQuery: "建立查詢", diff --git a/apps/desktop/src/lib/__tests__/shortcutRegistry.spec.ts b/apps/desktop/src/lib/__tests__/shortcutRegistry.spec.ts new file mode 100644 index 0000000000..12cf92f586 --- /dev/null +++ b/apps/desktop/src/lib/__tests__/shortcutRegistry.spec.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from "vitest"; +import { DEFAULT_SHORTCUT_SETTINGS, SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings, type ShortcutActionId } from "@/lib/shortcutRegistry"; + +describe("shortcutRegistry editor actions", () => { + const formatterEditorActionIds: ShortcutActionId[] = ["formatSql", "indentMore", "indentLess", "duplicateLine", "deleteLine", "moveLineUp", "moveLineDown", "copyLineUp", "copyLineDown", "undo", "redo", "selectAll"]; + + it("registers formatter editor shortcuts in the generic editor scope", () => { + for (const actionId of formatterEditorActionIds) { + const definition = SHORTCUT_DEFINITIONS.find((item) => item.id === actionId); + + expect(definition?.scope).toBe("editor"); + expect(DEFAULT_SHORTCUT_SETTINGS[actionId]).toBe(definition?.defaultShortcut); + } + }); + + it("normalizes missing formatter editor shortcuts to their generic defaults", () => { + const shortcuts = normalizeShortcutSettings({ executeSql: "Mod+Shift+Enter" }); + + expect(shortcuts.executeSql).toBe("Mod+Shift+Enter"); + expect(shortcuts.formatSql).toBe("Shift+Mod+F"); + expect(shortcuts.indentMore).toBe(""); + expect(shortcuts.indentLess).toBe("Shift+Tab"); + expect(shortcuts.duplicateLine).toBe("Mod+D"); + expect(shortcuts.deleteLine).toBe("Shift+Mod+K"); + expect(shortcuts.moveLineUp).toBe("Alt+ArrowUp"); + expect(shortcuts.moveLineDown).toBe("Alt+ArrowDown"); + expect(shortcuts.copyLineUp).toBe("Shift+Alt+ArrowUp"); + expect(shortcuts.copyLineDown).toBe("Shift+Alt+ArrowDown"); + expect(shortcuts.undo).toBe("Mod+Z"); + expect(shortcuts.redo).toBe("Shift+Mod+Z"); + expect(shortcuts.selectAll).toBe("Mod+A"); + }); + + it("detects conflicts between formatter editor shortcuts and other editor shortcuts", () => { + const shortcuts = normalizeShortcutSettings({ duplicateLine: "Mod+F" }); + + expect(findShortcutConflict("duplicateLine", shortcuts.duplicateLine, shortcuts)).toBe("find"); + }); +}); diff --git a/apps/desktop/src/lib/__tests__/sqlFormatterConfig.spec.ts b/apps/desktop/src/lib/__tests__/sqlFormatterConfig.spec.ts new file mode 100644 index 0000000000..8cdfd12de2 --- /dev/null +++ b/apps/desktop/src/lib/__tests__/sqlFormatterConfig.spec.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vitest"; +import { DEFAULT_SQL_FORMATTER_SETTINGS, parseSqlFormatterConfig, serializeSqlFormatterConfig } from "@/lib/sqlFormatterConfig"; + +describe("sqlFormatterConfig shortcut storage", () => { + it("does not serialize JSON editor shortcut settings", () => { + const config = JSON.parse(serializeSqlFormatterConfig(DEFAULT_SQL_FORMATTER_SETTINGS)); + + expect(config.editor).toBeUndefined(); + }); + + it("ignores legacy JSON editor shortcut settings on import", () => { + const result = parseSqlFormatterConfig( + JSON.stringify({ + version: 1, + formatter: "sql-formatter", + options: {}, + editor: { + scope: "legacyJsonEditorScope", + shortcuts: [{ id: "unknownLegacyShortcut", enabled: "yes" }], + }, + }), + ); + + expect(result.ok).toBe(true); + }); +}); diff --git a/apps/desktop/src/lib/shortcutRegistry.ts b/apps/desktop/src/lib/shortcutRegistry.ts index 9e171ec7b1..822cb558fc 100644 --- a/apps/desktop/src/lib/shortcutRegistry.ts +++ b/apps/desktop/src/lib/shortcutRegistry.ts @@ -1,7 +1,19 @@ export type ShortcutActionId = | "executeSql" + | "formatSql" | "saveSql" | "acceptCompletion" + | "indentMore" + | "indentLess" + | "duplicateLine" + | "deleteLine" + | "moveLineUp" + | "moveLineDown" + | "copyLineUp" + | "copyLineDown" + | "undo" + | "redo" + | "selectAll" | "copyCurrentRow" | "deleteCurrentRow" | "newQuery" @@ -36,6 +48,12 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [ scope: "editor", defaultShortcut: "Mod+Enter", }, + { + id: "formatSql", + labelKey: "settings.shortcutFormatSql", + scope: "editor", + defaultShortcut: "Shift+Mod+F", + }, { id: "saveSql", labelKey: "settings.shortcutSaveSql", @@ -48,6 +66,72 @@ export const SHORTCUT_DEFINITIONS: ShortcutDefinition[] = [ scope: "editor", defaultShortcut: "Tab", }, + { + id: "indentMore", + labelKey: "settings.shortcutIndentMore", + scope: "editor", + defaultShortcut: "", + }, + { + id: "indentLess", + labelKey: "settings.shortcutIndentLess", + scope: "editor", + defaultShortcut: "Shift+Tab", + }, + { + id: "duplicateLine", + labelKey: "settings.shortcutDuplicateLine", + scope: "editor", + defaultShortcut: "Mod+D", + }, + { + id: "deleteLine", + labelKey: "settings.shortcutDeleteLine", + scope: "editor", + defaultShortcut: "Shift+Mod+K", + }, + { + id: "moveLineUp", + labelKey: "settings.shortcutMoveLineUp", + scope: "editor", + defaultShortcut: "Alt+ArrowUp", + }, + { + id: "moveLineDown", + labelKey: "settings.shortcutMoveLineDown", + scope: "editor", + defaultShortcut: "Alt+ArrowDown", + }, + { + id: "copyLineUp", + labelKey: "settings.shortcutCopyLineUp", + scope: "editor", + defaultShortcut: "Shift+Alt+ArrowUp", + }, + { + id: "copyLineDown", + labelKey: "settings.shortcutCopyLineDown", + scope: "editor", + defaultShortcut: "Shift+Alt+ArrowDown", + }, + { + id: "undo", + labelKey: "settings.shortcutUndo", + scope: "editor", + defaultShortcut: "Mod+Z", + }, + { + id: "redo", + labelKey: "settings.shortcutRedo", + scope: "editor", + defaultShortcut: "Shift+Mod+Z", + }, + { + id: "selectAll", + labelKey: "settings.shortcutSelectAll", + scope: "editor", + defaultShortcut: "Mod+A", + }, { id: "copyCurrentRow", labelKey: "settings.shortcutCopyCurrentRow", diff --git a/apps/desktop/src/lib/sqlFormatterConfig.ts b/apps/desktop/src/lib/sqlFormatterConfig.ts index c59ad695ba..a6ac64e1d2 100644 --- a/apps/desktop/src/lib/sqlFormatterConfig.ts +++ b/apps/desktop/src/lib/sqlFormatterConfig.ts @@ -1,6 +1,5 @@ export const SQL_FORMATTER_CONFIG_VERSION = 1; export const SQL_FORMATTER_CONFIG_FORMATTER = "sql-formatter"; -export const SQL_FORMATTER_EDITOR_SCOPE = "sqlFormatterConfigJsonEditor"; const CASE_VALUES = ["preserve", "upper", "lower"] as const; const INDENT_STYLE_VALUES = ["standard", "tabularLeft", "tabularRight"] as const; @@ -8,7 +7,6 @@ const LOGICAL_OPERATOR_NEWLINE_VALUES = ["before", "after"] as const; const TAB_WIDTH_VALUES = [2, 4] as const; const EXPRESSION_WIDTH_VALUES = [50, 80, 120] as const; const LINES_BETWEEN_QUERIES_VALUES = [0, 1, 2] as const; -const SQL_FORMATTER_PLATFORM_VALUES = ["windows", "linux", "macos"] as const; const SQL_FORMATTER_PARAM_TYPE_MARKERS = ["?", ":", "$"] as const; const SQL_FORMATTER_NAMED_PARAM_TYPE_MARKERS = [":", "@", "$"] as const; const SQL_FORMATTER_LEGACY_OPTION_KEYS = new Set(["params"]); @@ -19,7 +17,6 @@ export type SqlFormatterLogicalOperatorNewline = (typeof LOGICAL_OPERATOR_NEWLIN export type SqlFormatterTabWidth = (typeof TAB_WIDTH_VALUES)[number]; export type SqlFormatterExpressionWidth = (typeof EXPRESSION_WIDTH_VALUES)[number]; export type SqlFormatterLinesBetweenQueries = (typeof LINES_BETWEEN_QUERIES_VALUES)[number]; -export type SqlFormatterPlatform = (typeof SQL_FORMATTER_PLATFORM_VALUES)[number]; export interface SqlFormatterCustomParameter { regex: string; @@ -49,60 +46,15 @@ export interface SqlFormatterOptionSettings { paramTypes: SqlFormatterParamTypes | null; } -export type SqlFormatterEditorShortcutId = "find" | "replace" | "indentMore" | "indentLess" | "duplicateLine" | "deleteLine" | "moveLineUp" | "moveLineDown" | "copyLineUp" | "copyLineDown" | "undo" | "redo" | "selectAll" | "formatJson" | "applyConfig"; - -export type SqlFormatterEditorShortcutAction = "openSearchPanel" | "indentMore" | "indentLess" | "copyLineDown" | "copyLineUp" | "deleteLine" | "moveLineUp" | "moveLineDown" | "undo" | "redo" | "selectAll" | "formatJson" | "applyJsonDraft"; - -export interface SqlFormatterEditorShortcutKeys { - windows: string; - linux: string; - macos: string; -} - -export interface SqlFormatterEditorShortcut { - id: SqlFormatterEditorShortcutId; - action: SqlFormatterEditorShortcutAction; - keys: SqlFormatterEditorShortcutKeys; - enabled: boolean; -} - -export interface SqlFormatterEditorSettings { - scope: typeof SQL_FORMATTER_EDITOR_SCOPE; - platforms: SqlFormatterPlatform[]; - shortcuts: SqlFormatterEditorShortcut[]; -} - -export interface SqlFormatterSettings extends SqlFormatterOptionSettings { - editor: SqlFormatterEditorSettings; -} +export type SqlFormatterSettings = SqlFormatterOptionSettings; export interface SqlFormatterConfigFile { version: typeof SQL_FORMATTER_CONFIG_VERSION; formatter: typeof SQL_FORMATTER_CONFIG_FORMATTER; options: SqlFormatterOptionSettings; - editor: SqlFormatterEditorSettings; } export type SqlFormatterConfigParseResult = { ok: true; settings: SqlFormatterSettings } | { ok: false; message: string }; -export type SqlFormatterEditorValidationResult = { ok: true } | { ok: false; message: string }; - -export const DEFAULT_SQL_FORMATTER_EDITOR_SHORTCUTS: SqlFormatterEditorShortcut[] = [ - { id: "find", action: "openSearchPanel", keys: { windows: "Ctrl+F", linux: "Ctrl+F", macos: "Cmd+F" }, enabled: true }, - { id: "replace", action: "openSearchPanel", keys: { windows: "Ctrl+H", linux: "Ctrl+H", macos: "Cmd+Option+F" }, enabled: true }, - { id: "indentMore", action: "indentMore", keys: { windows: "Tab", linux: "Tab", macos: "Tab" }, enabled: true }, - { id: "indentLess", action: "indentLess", keys: { windows: "Shift+Tab", linux: "Shift+Tab", macos: "Shift+Tab" }, enabled: true }, - { id: "duplicateLine", action: "copyLineDown", keys: { windows: "Ctrl+D", linux: "Ctrl+D", macos: "Cmd+D" }, enabled: true }, - { id: "deleteLine", action: "deleteLine", keys: { windows: "Ctrl+Shift+K", linux: "Ctrl+Shift+K", macos: "Cmd+Shift+K" }, enabled: true }, - { id: "moveLineUp", action: "moveLineUp", keys: { windows: "Alt+Up", linux: "Alt+Up", macos: "Option+Up" }, enabled: true }, - { id: "moveLineDown", action: "moveLineDown", keys: { windows: "Alt+Down", linux: "Alt+Down", macos: "Option+Down" }, enabled: true }, - { id: "copyLineUp", action: "copyLineUp", keys: { windows: "Shift+Alt+Up", linux: "Shift+Alt+Up", macos: "Shift+Option+Up" }, enabled: true }, - { id: "copyLineDown", action: "copyLineDown", keys: { windows: "Shift+Alt+Down", linux: "Shift+Alt+Down", macos: "Shift+Option+Down" }, enabled: true }, - { id: "undo", action: "undo", keys: { windows: "Ctrl+Z", linux: "Ctrl+Z", macos: "Cmd+Z" }, enabled: true }, - { id: "redo", action: "redo", keys: { windows: "Ctrl+Y", linux: "Ctrl+Shift+Z", macos: "Cmd+Shift+Z" }, enabled: true }, - { id: "selectAll", action: "selectAll", keys: { windows: "Ctrl+A", linux: "Ctrl+A", macos: "Cmd+A" }, enabled: true }, - { id: "formatJson", action: "formatJson", keys: { windows: "Shift+Alt+F", linux: "Shift+Alt+F", macos: "Shift+Cmd+F" }, enabled: true }, - { id: "applyConfig", action: "applyJsonDraft", keys: { windows: "Ctrl+S", linux: "Ctrl+S", macos: "Cmd+S" }, enabled: true }, -]; export const DEFAULT_SQL_FORMATTER_SETTINGS: SqlFormatterSettings = { keywordCase: "upper", @@ -118,11 +70,6 @@ export const DEFAULT_SQL_FORMATTER_SETTINGS: SqlFormatterSettings = { denseOperators: false, newlineBeforeSemicolon: false, paramTypes: null, - editor: { - scope: SQL_FORMATTER_EDITOR_SCOPE, - platforms: [...SQL_FORMATTER_PLATFORM_VALUES], - shortcuts: cloneShortcuts(DEFAULT_SQL_FORMATTER_EDITOR_SHORTCUTS), - }, }; const SQL_FORMATTER_OPTION_KEYS = new Set([ @@ -219,161 +166,6 @@ function normalizeParamTypes(value: unknown, fallback: SqlFormatterParamTypes | }; } -function cloneShortcuts(shortcuts: readonly SqlFormatterEditorShortcut[]): SqlFormatterEditorShortcut[] { - return shortcuts.map((shortcut) => ({ - id: shortcut.id, - action: shortcut.action, - keys: { ...shortcut.keys }, - enabled: shortcut.enabled, - })); -} - -function normalizeShortcutKeys(value: unknown, fallback: SqlFormatterEditorShortcutKeys): SqlFormatterEditorShortcutKeys { - const input = isObject(value) ? value : {}; - return { - windows: typeof input.windows === "string" ? input.windows.trim() : fallback.windows, - linux: typeof input.linux === "string" ? input.linux.trim() : fallback.linux, - macos: typeof input.macos === "string" ? input.macos.trim() : fallback.macos, - }; -} - -function isCompatibleShortcutAction(shortcut: Record, fallback: SqlFormatterEditorShortcut): boolean { - if (shortcut.action === undefined || shortcut.action === fallback.action || shortcut.action === fallback.id) return true; - return fallback.id === "replace" && shortcut.action === "openReplacePanel"; -} - -export function sqlFormatterPlatformFromNavigator(platform = globalThis.navigator?.platform || ""): SqlFormatterPlatform { - const normalized = platform.toLowerCase(); - if (normalized.includes("mac")) return "macos"; - if (normalized.includes("linux")) return "linux"; - return "windows"; -} - -function keyPartToCodeMirror(part: string): string | null { - const normalized = part.trim().toLowerCase(); - if (normalized === "ctrl" || normalized === "control") return "Ctrl"; - if (normalized === "cmd" || normalized === "command") return "Mod"; - if (normalized === "option" || normalized === "alt") return "Alt"; - if (normalized === "shift") return "Shift"; - if (normalized === "up") return "ArrowUp"; - if (normalized === "down") return "ArrowDown"; - if (normalized === "left") return "ArrowLeft"; - if (normalized === "right") return "ArrowRight"; - if (normalized === "esc") return "Escape"; - if (normalized === "enter" || normalized === "return") return "Enter"; - if (normalized === "del") return "Delete"; - if (normalized === "space") return "Space"; - if (normalized === "pageup") return "PageUp"; - if (normalized === "pagedown") return "PageDown"; - if (["tab", "escape", "backspace", "delete", "home", "end"].includes(normalized)) return normalized[0].toUpperCase() + normalized.slice(1); - if (/^f(?:[1-9]|1\d|2[0-4])$/.test(normalized)) return normalized.toUpperCase(); - if (/^[a-z0-9]$/.test(normalized)) return normalized; - return null; -} - -export function sqlFormatterShortcutDisplayKeyToCodeMirrorKey(value: string): string | null { - const parts = value - .split("+") - .map((part) => part.trim()) - .filter(Boolean); - if (!parts.length) return null; - - const converted = parts.map(keyPartToCodeMirror); - if (converted.some((part) => !part)) return null; - - const key = converted[converted.length - 1]; - if (!key || ["Ctrl", "Mod", "Alt", "Shift"].includes(key)) return null; - - const modifiers = converted.slice(0, -1); - if (new Set(modifiers).size !== modifiers.length) return null; - if (modifiers.some((part) => part && !["Ctrl", "Mod", "Alt", "Shift"].includes(part))) return null; - - return [...modifiers, key].join("-"); -} - -function shortcutConflictKey(value: string): string | null { - return sqlFormatterShortcutDisplayKeyToCodeMirrorKey(value)?.toLowerCase() ?? null; -} - -export function validateSqlFormatterEditorSettings(value: unknown): SqlFormatterEditorValidationResult { - const settings = normalizeSqlFormatterEditorSettings(value); - const platformSet = new Set(settings.platforms); - - for (const shortcut of settings.shortcuts) { - if (!shortcut.enabled) continue; - for (const platform of settings.platforms) { - if (!shortcutConflictKey(shortcut.keys[platform])) return { ok: false, message: `Invalid editor shortcut value: ${shortcut.id}.` }; - } - } - - for (const platform of SQL_FORMATTER_PLATFORM_VALUES) { - if (!platformSet.has(platform)) continue; - const seen = new Map(); - for (const shortcut of settings.shortcuts) { - if (!shortcut.enabled) continue; - const key = shortcutConflictKey(shortcut.keys[platform]); - if (!key) continue; - const existing = seen.get(key); - if (existing) return { ok: false, message: `Duplicate editor shortcut: ${platform}:${shortcut.keys[platform]}.` }; - seen.set(key, shortcut.id); - } - } - - return { ok: true }; -} - -export function normalizeSqlFormatterEditorSettings(value: unknown): SqlFormatterEditorSettings { - const input = isObject(value) ? value : {}; - const shortcutsInput = Array.isArray(input.shortcuts) ? input.shortcuts.filter(isObject) : []; - const platforms = Array.isArray(input.platforms) ? input.platforms.filter((platform): platform is SqlFormatterPlatform => isStringChoice(platform, SQL_FORMATTER_PLATFORM_VALUES)) : [...SQL_FORMATTER_PLATFORM_VALUES]; - const normalizedPlatforms = platforms.length ? [...new Set(platforms)] : [...SQL_FORMATTER_PLATFORM_VALUES]; - - return { - scope: SQL_FORMATTER_EDITOR_SCOPE, - platforms: normalizedPlatforms, - shortcuts: DEFAULT_SQL_FORMATTER_EDITOR_SHORTCUTS.map((fallback) => { - const source = shortcutsInput.find((shortcut) => shortcut.id === fallback.id); - return { - id: fallback.id, - action: fallback.action, - keys: normalizeShortcutKeys(source?.keys, fallback.keys), - enabled: typeof source?.enabled === "boolean" ? source.enabled : fallback.enabled, - }; - }), - }; -} - -function validateEditorConfig(value: unknown): string | null { - if (value === undefined) return null; - if (!isObject(value)) return "Config editor must be a JSON object."; - if (value.scope !== undefined && value.scope !== SQL_FORMATTER_EDITOR_SCOPE) return "Unsupported editor scope."; - if (value.platforms !== undefined && (!Array.isArray(value.platforms) || !value.platforms.every((platform) => isStringChoice(platform, SQL_FORMATTER_PLATFORM_VALUES)))) { - return "Invalid editor platforms."; - } - if (value.shortcuts === undefined) return null; - if (!Array.isArray(value.shortcuts)) return "Config editor shortcuts must be an array."; - - for (const shortcut of value.shortcuts) { - if (!isObject(shortcut) || typeof shortcut.id !== "string") return "Invalid editor shortcut value."; - const fallback = DEFAULT_SQL_FORMATTER_EDITOR_SHORTCUTS.find((item) => item.id === shortcut.id); - if (!fallback) return `Unknown editor shortcut: ${shortcut.id}.`; - if (!isCompatibleShortcutAction(shortcut, fallback)) return `Invalid editor shortcut value: ${shortcut.id}.`; - if (shortcut.enabled !== undefined && typeof shortcut.enabled !== "boolean") return `Invalid editor shortcut value: ${shortcut.id}.`; - if (shortcut.keys !== undefined) { - if (!isObject(shortcut.keys)) return `Invalid editor shortcut value: ${shortcut.id}.`; - const keys = Object.entries(shortcut.keys); - const hasInvalidKey = keys.some(([platform, key]) => !isStringChoice(platform, SQL_FORMATTER_PLATFORM_VALUES) || typeof key !== "string" || !key.trim()); - if (hasInvalidKey) { - return `Invalid editor shortcut value: ${shortcut.id}.`; - } - } - } - - const normalized = normalizeSqlFormatterEditorSettings(value); - const validation = validateSqlFormatterEditorSettings(normalized); - return validation.ok ? null : validation.message; -} - export function sqlFormatterOptionSettings(settings: unknown): SqlFormatterOptionSettings { const input = isObject(settings) ? settings : {}; return { @@ -396,10 +188,7 @@ export function sqlFormatterOptionSettings(settings: unknown): SqlFormatterOptio export function normalizeSqlFormatterSettings(value: unknown): SqlFormatterSettings { const input = isObject(value) ? value : {}; const optionSource = isObject(input.options) ? input.options : input; - return { - ...sqlFormatterOptionSettings(optionSource), - editor: normalizeSqlFormatterEditorSettings(input.editor), - }; + return sqlFormatterOptionSettings(optionSource); } export function sqlFormatterConfigFile(settings: unknown): SqlFormatterConfigFile { @@ -408,7 +197,6 @@ export function sqlFormatterConfigFile(settings: unknown): SqlFormatterConfigFil version: SQL_FORMATTER_CONFIG_VERSION, formatter: SQL_FORMATTER_CONFIG_FORMATTER, options: sqlFormatterOptionSettings(normalized), - editor: normalizeSqlFormatterEditorSettings(normalized.editor), }; } @@ -440,10 +228,7 @@ export function parseSqlFormatterConfig(text: string): SqlFormatterConfigParseRe }); if (invalidOption) return { ok: false, message: `Invalid formatter option value: ${invalidOption[0]}.` }; - const editorError = validateEditorConfig(parsed.editor); - if (editorError) return { ok: false, message: editorError }; - - return { ok: true, settings: normalizeSqlFormatterSettings({ ...parsed.options, editor: parsed.editor }) }; + return { ok: true, settings: normalizeSqlFormatterSettings(parsed.options) }; } export function syncSqlFormatterConfigDraft(text: string, syncSettings: (settings: SqlFormatterSettings) => void): SqlFormatterConfigParseResult { diff --git a/apps/desktop/src/lib/sqlFormatterConfigEditor.ts b/apps/desktop/src/lib/sqlFormatterConfigEditor.ts deleted file mode 100644 index 553cf5084b..0000000000 --- a/apps/desktop/src/lib/sqlFormatterConfigEditor.ts +++ /dev/null @@ -1,110 +0,0 @@ -import type { Command, KeyBinding } from "@codemirror/view"; -import { normalizeSqlFormatterEditorSettings, sqlFormatterPlatformFromNavigator, sqlFormatterShortcutDisplayKeyToCodeMirrorKey, type SqlFormatterEditorSettings, type SqlFormatterEditorShortcutAction, type SqlFormatterEditorShortcutId } from "@/lib/sqlFormatterConfig"; - -export interface SqlFormatterConfigEditorCommands { - indentMore: Command; - indentLess: Command; - copyLineDown: Command; - copyLineUp: Command; - deleteLine: Command; - moveLineUp: Command; - moveLineDown: Command; - undo: Command; - redo: Command; - selectAll: Command; - openSearchPanel: Command; -} - -export interface SqlFormatterConfigEditorActions { - apply: Command; - formatJson: Command; -} - -const shortcutLabelKeys: Record = { - find: "settings.sqlFormatterShortcutFind", - replace: "settings.sqlFormatterShortcutReplace", - indentMore: "settings.sqlFormatterShortcutIndentMore", - indentLess: "settings.sqlFormatterShortcutIndentLess", - duplicateLine: "settings.sqlFormatterShortcutDuplicateLine", - deleteLine: "settings.sqlFormatterShortcutDeleteLine", - moveLineUp: "settings.sqlFormatterShortcutMoveLineUp", - moveLineDown: "settings.sqlFormatterShortcutMoveLineDown", - copyLineUp: "settings.sqlFormatterShortcutCopyLineUp", - copyLineDown: "settings.sqlFormatterShortcutCopyLineDown", - undo: "settings.sqlFormatterShortcutUndo", - redo: "settings.sqlFormatterShortcutRedo", - selectAll: "settings.sqlFormatterShortcutSelectAll", - formatJson: "settings.sqlFormatterShortcutFormatJson", - applyConfig: "settings.sqlFormatterShortcutApply", -}; - -export function sqlFormatterConfigShortcutLabelKey(id: SqlFormatterEditorShortcutId): string { - return shortcutLabelKeys[id]; -} - -function commandForAction(commands: SqlFormatterConfigEditorCommands, actions: SqlFormatterConfigEditorActions, action: SqlFormatterEditorShortcutAction): Command { - switch (action) { - case "indentMore": - return commands.indentMore; - case "indentLess": - return commands.indentLess; - case "copyLineDown": - return commands.copyLineDown; - case "copyLineUp": - return commands.copyLineUp; - case "deleteLine": - return commands.deleteLine; - case "moveLineUp": - return commands.moveLineUp; - case "moveLineDown": - return commands.moveLineDown; - case "undo": - return commands.undo; - case "redo": - return commands.redo; - case "selectAll": - return commands.selectAll; - case "openSearchPanel": - return commands.openSearchPanel; - case "formatJson": - return actions.formatJson; - case "applyJsonDraft": - return actions.apply; - } -} - -export function createSqlFormatterConfigKeymap(commands: SqlFormatterConfigEditorCommands, actions: SqlFormatterConfigEditorActions, editorSettings?: SqlFormatterEditorSettings): KeyBinding[] { - const settings = normalizeSqlFormatterEditorSettings(editorSettings); - const platforms = new Set(settings.platforms); - - return settings.shortcuts - .filter((shortcut) => shortcut.enabled) - .map((shortcut) => { - const binding: KeyBinding = { - run: commandForAction(commands, actions, shortcut.action), - preventDefault: true, - }; - if (platforms.has("windows")) binding.win = sqlFormatterShortcutDisplayKeyToCodeMirrorKey(shortcut.keys.windows) ?? undefined; - if (platforms.has("linux")) binding.linux = sqlFormatterShortcutDisplayKeyToCodeMirrorKey(shortcut.keys.linux) ?? undefined; - if (platforms.has("macos")) binding.mac = sqlFormatterShortcutDisplayKeyToCodeMirrorKey(shortcut.keys.macos) ?? undefined; - return binding; - }); -} - -export interface SqlFormatterConfigShortcutRow { - id: string; - labelKey: string; - shortcut: string; -} - -export function sqlFormatterConfigShortcutRows(platform = globalThis.navigator?.platform || "", editorSettings?: SqlFormatterEditorSettings): SqlFormatterConfigShortcutRow[] { - const platformKey = sqlFormatterPlatformFromNavigator(platform); - - return normalizeSqlFormatterEditorSettings(editorSettings) - .shortcuts.filter((shortcut) => shortcut.enabled) - .map((shortcut) => ({ - id: shortcut.id, - labelKey: shortcutLabelKeys[shortcut.id], - shortcut: shortcut.keys[platformKey], - })); -} diff --git a/packages/app-tests/sqlFormatterConfig.test.ts b/packages/app-tests/sqlFormatterConfig.test.ts index eab44f78d1..10f968b6fe 100644 --- a/packages/app-tests/sqlFormatterConfig.test.ts +++ b/packages/app-tests/sqlFormatterConfig.test.ts @@ -1,8 +1,8 @@ import assert from "node:assert/strict"; import { test } from "vitest"; -import { DEFAULT_SQL_FORMATTER_SETTINGS, normalizeSqlFormatterSettings, parseSqlFormatterConfig, serializeSqlFormatterConfig, sqlFormatterOptions, syncSqlFormatterConfigDraft, validateSqlFormatterEditorSettings } from "../../apps/desktop/src/lib/sqlFormatterConfig.ts"; +import { DEFAULT_SQL_FORMATTER_SETTINGS, normalizeSqlFormatterSettings, parseSqlFormatterConfig, serializeSqlFormatterConfig, sqlFormatterOptions, syncSqlFormatterConfigDraft } from "../../apps/desktop/src/lib/sqlFormatterConfig.ts"; -const { editor: defaultEditorSettings, ...defaultOptionSettings } = DEFAULT_SQL_FORMATTER_SETTINGS; +const defaultOptionSettings = DEFAULT_SQL_FORMATTER_SETTINGS; test("normalizes empty formatter settings to defaults", () => { assert.deepEqual(normalizeSqlFormatterSettings({}), DEFAULT_SQL_FORMATTER_SETTINGS); @@ -59,13 +59,7 @@ test("keeps valid formatter settings and clamps invalid values", () => { paramTypes: { named: ["#"] }, editor: { shortcuts: [{ id: "duplicateLine", keys: { windows: "Ctrl+W", linux: "Ctrl+W", macos: "Cmd+W" }, enabled: false }] }, }), - { - ...DEFAULT_SQL_FORMATTER_SETTINGS, - editor: { - ...defaultEditorSettings, - shortcuts: defaultEditorSettings.shortcuts.map((shortcut) => (shortcut.id === "duplicateLine" ? { ...shortcut, keys: { windows: "Ctrl+W", linux: "Ctrl+W", macos: "Cmd+W" }, enabled: false } : shortcut)), - }, - }, + DEFAULT_SQL_FORMATTER_SETTINGS, ); }); @@ -84,7 +78,6 @@ test("serializes formatter config as a stable versioned envelope", () => { ...defaultOptionSettings, keywordCase: "lower", }, - editor: defaultEditorSettings, }, null, 2, @@ -114,9 +107,9 @@ test("parses valid formatter config files", () => { paramTypes: { named: [":"], quoted: ["@"], positional: true }, }, editor: { - scope: "sqlFormatterConfigJsonEditor", + scope: "legacyJsonEditorScope", platforms: ["windows", "macos"], - shortcuts: [{ id: "duplicateLine", action: "copyLineDown", keys: { windows: "Ctrl+W", linux: "Ctrl+W", macos: "Cmd+W" }, enabled: true }], + shortcuts: [{ id: "unknownLegacyShortcut", action: "copyLineDown", keys: { windows: "", linux: "Ctrl+W", macos: "Cmd+W" }, enabled: "yes" }], }, }), ); @@ -137,52 +130,24 @@ test("parses valid formatter config files", () => { denseOperators: false, newlineBeforeSemicolon: true, paramTypes: { named: [":"], quoted: ["@"], positional: true }, - editor: { - ...defaultEditorSettings, - platforms: ["windows", "macos"], - shortcuts: defaultEditorSettings.shortcuts.map((shortcut) => (shortcut.id === "duplicateLine" ? { ...shortcut, keys: { windows: "Ctrl+W", linux: "Ctrl+W", macos: "Cmd+W" } } : shortcut)), - }, }); }); -test("parses user-facing editor shortcut actions as known shortcut ids", () => { - for (const action of ["replace", "openReplacePanel"]) { - const result = parseSqlFormatterConfig( - JSON.stringify({ - version: 1, - formatter: "sql-formatter", - options: {}, - editor: { - shortcuts: [{ id: "replace", action, keys: { windows: "Ctrl+R", linux: "Ctrl+R", macos: "Cmd+R" }, enabled: true }], - }, - }), - ); - - assert.equal(result.ok, true); - if (result.ok) { - const shortcut = result.settings.editor.shortcuts.find((item) => item.id === "replace"); - assert.equal(shortcut?.action, "openSearchPanel"); - assert.deepEqual(shortcut?.keys, { windows: "Ctrl+R", linux: "Ctrl+R", macos: "Cmd+R" }); - } - } -}); - -test("parses partial editor shortcut keys and fills missing platforms from defaults", () => { +test("ignores legacy editor shortcut fields in formatter config files", () => { const result = parseSqlFormatterConfig( JSON.stringify({ version: 1, formatter: "sql-formatter", options: {}, editor: { - shortcuts: [{ id: "replace", keys: { windows: "Ctrl+R" }, enabled: true }], + shortcuts: [{ id: "unknown", keys: { windows: "" }, enabled: "not-a-boolean" }], }, }), ); assert.equal(result.ok, true); if (result.ok) { - const shortcut = result.settings.editor.shortcuts.find((item) => item.id === "replace"); - assert.deepEqual(shortcut?.keys, { windows: "Ctrl+R", linux: "Ctrl+H", macos: "Cmd+Option+F" }); + assert.deepEqual(result.settings, DEFAULT_SQL_FORMATTER_SETTINGS); } }); @@ -218,57 +183,6 @@ test("rejects invalid known formatter option values when parsing config files", if (!invalidParamTypes.ok) assert.match(invalidParamTypes.message, /paramTypes/); }); -test("rejects invalid editor shortcut config", () => { - const unknownShortcut = parseSqlFormatterConfig( - JSON.stringify({ - version: 1, - formatter: "sql-formatter", - options: {}, - editor: { shortcuts: [{ id: "unknown", action: "copyLineDown", keys: { windows: "Ctrl+D", linux: "Ctrl+D", macos: "Cmd+D" }, enabled: true }] }, - }), - ); - assert.equal(unknownShortcut.ok, false); - if (!unknownShortcut.ok) assert.match(unknownShortcut.message, /unknown/); - - const invalidKeys = parseSqlFormatterConfig( - JSON.stringify({ - version: 1, - formatter: "sql-formatter", - options: {}, - editor: { shortcuts: [{ id: "duplicateLine", action: "copyLineDown", keys: { windows: "", linux: "Ctrl+D", macos: "Cmd+D" }, enabled: true }] }, - }), - ); - assert.equal(invalidKeys.ok, false); - if (!invalidKeys.ok) assert.match(invalidKeys.message, /duplicateLine/); - - const duplicateKeys = parseSqlFormatterConfig( - JSON.stringify({ - version: 1, - formatter: "sql-formatter", - options: {}, - editor: { - shortcuts: [ - { id: "find", action: "openSearchPanel", keys: { windows: "Ctrl+D", linux: "Ctrl+F", macos: "Cmd+F" }, enabled: true }, - { id: "duplicateLine", action: "copyLineDown", keys: { windows: "Ctrl+D", linux: "Ctrl+D", macos: "Cmd+D" }, enabled: true }, - ], - }, - }), - ); - assert.equal(duplicateKeys.ok, false); - if (!duplicateKeys.ok) assert.match(duplicateKeys.message, /Duplicate/); -}); - -test("validates editor shortcut settings outside config import", () => { - assert.deepEqual(validateSqlFormatterEditorSettings(DEFAULT_SQL_FORMATTER_SETTINGS.editor), { ok: true }); - assert.equal( - validateSqlFormatterEditorSettings({ - ...DEFAULT_SQL_FORMATTER_SETTINGS.editor, - shortcuts: DEFAULT_SQL_FORMATTER_SETTINGS.editor.shortcuts.map((shortcut) => (shortcut.id === "duplicateLine" ? { ...shortcut, keys: { ...shortcut.keys, windows: "Ctrl+" } } : shortcut)), - }).ok, - false, - ); -}); - test("syncs valid JSON drafts so outer settings apply can persist them", () => { let synced = DEFAULT_SQL_FORMATTER_SETTINGS; const result = syncSqlFormatterConfigDraft( @@ -280,7 +194,6 @@ test("syncs valid JSON drafts so outer settings apply can persist them", () => { keywordCase: "lower", tabWidth: 4, }, - editor: defaultEditorSettings, }), (settings) => { synced = settings; @@ -305,7 +218,6 @@ test("does not sync invalid JSON drafts", () => { ...defaultOptionSettings, keywordCase: "camel", }, - editor: defaultEditorSettings, }), (settings) => { synced = settings; diff --git a/packages/app-tests/sqlFormatterConfigEditor.test.ts b/packages/app-tests/sqlFormatterConfigEditor.test.ts deleted file mode 100644 index 21097f610d..0000000000 --- a/packages/app-tests/sqlFormatterConfigEditor.test.ts +++ /dev/null @@ -1,106 +0,0 @@ -import assert from "node:assert/strict"; -import { test } from "vitest"; -import { DEFAULT_SQL_FORMATTER_SETTINGS } from "../../apps/desktop/src/lib/sqlFormatterConfig.ts"; -import { createSqlFormatterConfigKeymap, sqlFormatterConfigShortcutRows } from "../../apps/desktop/src/lib/sqlFormatterConfigEditor.ts"; - -const commands = { - indentMore: () => true, - indentLess: () => true, - copyLineDown: () => true, - copyLineUp: () => true, - deleteLine: () => true, - moveLineUp: () => true, - moveLineDown: () => true, - undo: () => true, - redo: () => true, - selectAll: () => true, - openSearchPanel: () => true, -}; -const actions = { - apply: () => true, - formatJson: () => true, -}; -const otherCommand = () => true; - -function createBindings(editorSettings = DEFAULT_SQL_FORMATTER_SETTINGS.editor) { - return createSqlFormatterConfigKeymap(commands, actions, editorSettings); -} - -test("builds common SQL formatter config editor key bindings", () => { - const bindings = createBindings(); - - assert.deepEqual( - bindings.map((binding) => binding.win), - ["Ctrl-f", "Ctrl-h", "Tab", "Shift-Tab", "Ctrl-d", "Ctrl-Shift-k", "Alt-ArrowUp", "Alt-ArrowDown", "Shift-Alt-ArrowUp", "Shift-Alt-ArrowDown", "Ctrl-z", "Ctrl-y", "Ctrl-a", "Shift-Alt-f", "Ctrl-s"], - ); - assert.deepEqual( - bindings.map((binding) => binding.linux), - ["Ctrl-f", "Ctrl-h", "Tab", "Shift-Tab", "Ctrl-d", "Ctrl-Shift-k", "Alt-ArrowUp", "Alt-ArrowDown", "Shift-Alt-ArrowUp", "Shift-Alt-ArrowDown", "Ctrl-z", "Ctrl-Shift-z", "Ctrl-a", "Shift-Alt-f", "Ctrl-s"], - ); -}); - -test("sets search, format, and apply binding details", () => { - const bindings = createBindings(); - const searchBinding = bindings.find((binding) => binding.win === "Ctrl-h"); - const formatBinding = bindings.find((binding) => binding.win === "Shift-Alt-f"); - const applyBinding = bindings.find((binding) => binding.win === "Ctrl-s"); - - assert.equal(searchBinding?.mac, "Mod-Alt-f"); - assert.equal(searchBinding?.linux, "Ctrl-h"); - assert.equal(searchBinding?.preventDefault, true); - assert.equal(searchBinding?.run, commands.openSearchPanel); - assert.equal(formatBinding?.mac, "Shift-Mod-f"); - assert.equal(formatBinding?.preventDefault, true); - assert.equal(formatBinding?.run, actions.formatJson); - assert.equal(applyBinding?.mac, "Mod-s"); - assert.equal(applyBinding?.preventDefault, true); - assert.equal(applyBinding?.run, actions.apply); -}); - -test("keeps duplicate line before later Ctrl-d search bindings", () => { - const bindings = [...createBindings(), { win: "Ctrl-d", run: otherCommand }]; - const duplicateLineIndex = bindings.findIndex((binding) => binding.win === "Ctrl-d" && binding.run === commands.copyLineDown); - const searchKeymapIndex = bindings.findIndex((binding) => binding.win === "Ctrl-d" && binding.run === otherCommand); - - assert.notEqual(duplicateLineIndex, -1); - assert.notEqual(searchKeymapIndex, -1); - assert.equal(bindings[duplicateLineIndex]?.run, commands.copyLineDown); - assert.ok(duplicateLineIndex < searchKeymapIndex); -}); - -test("uses customized shortcut keys and skips disabled shortcuts", () => { - const editorSettings = { - ...DEFAULT_SQL_FORMATTER_SETTINGS.editor, - shortcuts: DEFAULT_SQL_FORMATTER_SETTINGS.editor.shortcuts.map((shortcut) => { - if (shortcut.id === "duplicateLine") return { ...shortcut, keys: { windows: "Ctrl+W", linux: "Ctrl+W", macos: "Cmd+W" } }; - if (shortcut.id === "deleteLine") return { ...shortcut, enabled: false }; - return shortcut; - }), - }; - - const bindings = createBindings(editorSettings); - assert.equal(bindings.find((binding) => binding.win === "Ctrl-w")?.run, commands.copyLineDown); - assert.equal(bindings.find((binding) => binding.linux === "Ctrl-w")?.run, commands.copyLineDown); - assert.equal(bindings.some((binding) => binding.win === "Ctrl-Shift-k"), false); -}); - -test("honors enabled platforms when building key bindings", () => { - const bindings = createBindings({ - ...DEFAULT_SQL_FORMATTER_SETTINGS.editor, - platforms: ["linux"], - }); - - assert.equal(bindings.every((binding) => !binding.win && !binding.mac && !!binding.linux), true); -}); - -test("shows platform-aware shortcut labels", () => { - const windowsRows = sqlFormatterConfigShortcutRows("Win32"); - const macRows = sqlFormatterConfigShortcutRows("MacIntel"); - - assert.equal(windowsRows.find((row) => row.id === "duplicateLine")?.shortcut, "Ctrl+D"); - assert.equal(macRows.find((row) => row.id === "duplicateLine")?.shortcut, "Cmd+D"); - assert.equal(windowsRows.find((row) => row.id === "formatJson")?.shortcut, "Shift+Alt+F"); - assert.equal(macRows.find((row) => row.id === "formatJson")?.shortcut, "Shift+Cmd+F"); - assert.equal(windowsRows.find((row) => row.id === "applyConfig")?.shortcut, "Ctrl+S"); - assert.equal(macRows.find((row) => row.id === "applyConfig")?.shortcut, "Cmd+S"); -});