diff --git a/crates-tauri/yaak-app/src/lib.rs b/crates-tauri/yaak-app/src/lib.rs index 2b1710cfd..5009597de 100644 --- a/crates-tauri/yaak-app/src/lib.rs +++ b/crates-tauri/yaak-app/src/lib.rs @@ -843,8 +843,10 @@ async fn cmd_send_ephemeral_request( } #[tauri::command] -async fn cmd_format_json(text: &str) -> YaakResult { - Ok(format_json(text, " ")) +async fn cmd_format_json(text: &str, indent: Option) -> YaakResult { + let n = indent.unwrap_or(2); + let indent_str = " ".repeat(n as usize); + Ok(format_json(text, &indent_str)) } #[tauri::command] diff --git a/crates/yaak-models/bindings/gen_models.ts b/crates/yaak-models/bindings/gen_models.ts index da1da73cf..6743c66a2 100644 --- a/crates/yaak-models/bindings/gen_models.ts +++ b/crates/yaak-models/bindings/gen_models.ts @@ -75,7 +75,7 @@ export type ProxySetting = { "type": "enabled", http: string, https: string, aut export type ProxySettingAuth = { user: string, password: string, }; -export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, clientCertificates: Array, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorSoftWrap: boolean, hideWindowControls: boolean, useNativeTitlebar: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, hideLicenseBadge: boolean, autoupdate: boolean, autoDownloadUpdates: boolean, checkNotifications: boolean, hotkeys: { [key in string]?: Array }, }; +export type Settings = { model: "settings", id: string, createdAt: string, updatedAt: string, appearance: string, clientCertificates: Array, coloredMethods: boolean, editorFont: string | null, editorFontSize: number, editorKeymap: EditorKeymap, editorIndentation: number, editorSoftWrap: boolean, hideWindowControls: boolean, useNativeTitlebar: boolean, interfaceFont: string | null, interfaceFontSize: number, interfaceScale: number, openWorkspaceNewWindow: boolean | null, proxy: ProxySetting | null, themeDark: string, themeLight: string, updateChannel: string, hideLicenseBadge: boolean, autoupdate: boolean, autoDownloadUpdates: boolean, checkNotifications: boolean, hotkeys: { [key in string]?: Array }, }; export type SyncState = { model: "sync_state", id: string, workspaceId: string, createdAt: string, updatedAt: string, flushedAt: string, modelId: string, checksum: string, relPath: string, syncDir: string, }; @@ -93,6 +93,6 @@ export type WebsocketMessageType = "text" | "binary"; export type WebsocketRequest = { model: "websocket_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record, authenticationType: string | null, description: string, headers: Array, message: string, name: string, sortPriority: number, url: string, urlParameters: Array, }; -export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, authentication: Record, authenticationType: string | null, description: string, headers: Array, name: string, encryptionKeyChallenge: string | null, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, settingDnsOverrides: Array, }; +export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, authentication: Record, authenticationType: string | null, description: string, headers: Array, name: string, encryptionKeyChallenge: string | null, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, }; export type WorkspaceMeta = { model: "workspace_meta", id: string, workspaceId: string, createdAt: string, updatedAt: string, encryptionKey: EncryptedKey | null, settingSyncDir: string | null, }; diff --git a/crates/yaak-models/migrations/20251127214940_add-editor-tab-indentation.sql b/crates/yaak-models/migrations/20251127214940_add-editor-tab-indentation.sql new file mode 100644 index 000000000..4fe8d4780 --- /dev/null +++ b/crates/yaak-models/migrations/20251127214940_add-editor-tab-indentation.sql @@ -0,0 +1 @@ +ALTER TABLE settings ADD COLUMN editor_indentation INTEGER DEFAULT 2 NOT NULL; \ No newline at end of file diff --git a/crates/yaak-models/src/models.rs b/crates/yaak-models/src/models.rs index 054017704..9a1403f29 100644 --- a/crates/yaak-models/src/models.rs +++ b/crates/yaak-models/src/models.rs @@ -146,6 +146,7 @@ pub struct Settings { pub editor_font: Option, pub editor_font_size: i32, pub editor_keymap: EditorKeymap, + pub editor_indentation: i32, pub editor_soft_wrap: bool, pub hide_window_controls: bool, // When true (primarily on Windows/Linux), use the native OS window title bar and controls @@ -204,6 +205,7 @@ impl UpsertModelInfo for Settings { (ClientCertificates, client_certificates.into()), (EditorFontSize, self.editor_font_size.into()), (EditorKeymap, self.editor_keymap.to_string().into()), + (EditorIndentation, self.editor_indentation.into()), (EditorSoftWrap, self.editor_soft_wrap.into()), (EditorFont, self.editor_font.into()), (InterfaceFont, self.interface_font.into()), @@ -232,6 +234,7 @@ impl UpsertModelInfo for Settings { SettingsIden::ClientCertificates, SettingsIden::EditorFontSize, SettingsIden::EditorKeymap, + SettingsIden::EditorIndentation, SettingsIden::EditorSoftWrap, SettingsIden::EditorFont, SettingsIden::InterfaceFontSize, @@ -271,6 +274,7 @@ impl UpsertModelInfo for Settings { editor_font_size: row.get("editor_font_size")?, editor_font: row.get("editor_font")?, editor_keymap: EditorKeymap::from_str(editor_keymap.as_str()).unwrap(), + editor_indentation: row.get("editor_indentation")?, editor_soft_wrap: row.get("editor_soft_wrap")?, interface_font_size: row.get("interface_font_size")?, interface_scale: row.get("interface_scale")?, diff --git a/crates/yaak-models/src/queries/settings.rs b/crates/yaak-models/src/queries/settings.rs index b44aee3ab..8d9a06688 100644 --- a/crates/yaak-models/src/queries/settings.rs +++ b/crates/yaak-models/src/queries/settings.rs @@ -24,6 +24,7 @@ impl<'a> DbContext<'a> { editor_font_size: 12, editor_font: None, editor_keymap: EditorKeymap::Default, + editor_indentation: 2, editor_soft_wrap: true, interface_font_size: 14, interface_scale: 1.0, diff --git a/src-web/components/Settings/SettingsInterface.tsx b/src-web/components/Settings/SettingsInterface.tsx index 5d9541251..11122dafd 100644 --- a/src-web/components/Settings/SettingsInterface.tsx +++ b/src-web/components/Settings/SettingsInterface.tsx @@ -32,6 +32,8 @@ const keymaps: { value: EditorKeymap; label: string }[] = [ { value: 'emacs', label: 'Emacs' }, ]; +const tabIndentOptions = [2, 4, 6, 8, 10].map((n) => ({ label: `${n}`, value: `${n}` })); + export function SettingsInterface() { const workspace = useAtomValue(activeWorkspaceAtom); const settings = useAtomValue(settingsAtom); @@ -148,6 +150,18 @@ export function SettingsInterface() { options={keymaps} onChange={(v) => patchModel(settings, { editorKeymap: v })} /> +