diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c7a894f..6be8f1b 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2499,9 +2499,9 @@ dependencies = [ [[package]] name = "handy-keys" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f85c247daebc113bb7128afa9ee19eb83b9a6d1301772b89111328ab856186" +checksum = "f9d80f27a8566d1dd16cef20dd0a96247d2982fc2e03ef728ea842808b130d94" dependencies = [ "bitflags 2.10.0", "block2 0.6.2", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2d7777a..f9001fe 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -69,7 +69,7 @@ rusqlite = { version = "0.37", features = ["bundled"] } tar = "0.4.44" flate2 = "1.0" transcribe-rs = { version = "0.2.3", features = ["whisper", "parakeet", "moonshine", "sense_voice"] } -handy-keys = "0.1.4" +handy-keys = "0.2.0" ferrous-opencc = "0.2.3" specta = "=2.0.0-rc.22" specta-typescript = "0.0.9" diff --git a/src/lib/utils/keyboard.ts b/src/lib/utils/keyboard.ts index 08af392..c3de55b 100644 --- a/src/lib/utils/keyboard.ts +++ b/src/lib/utils/keyboard.ts @@ -154,17 +154,52 @@ export const getKeyName = ( return `unknown-${e.keyCode || e.which || 0}`; }; +/** + * Capitalize a key name for display (e.g. "space" -> "Space", "f1" -> "F1") + */ +const capitalizeKey = (key: string): string => { + // fn key: keep lowercase + if (key === "fn") return "fn"; + // Function keys: f1 -> F1 + if (/^f\d+$/.test(key)) return key.toUpperCase(); + // Single char: a -> A + if (key.length === 1) return key.toUpperCase(); + // Multi-word: capitalize first letter of each word + return key.replace(/\b\w/g, (c) => c.toUpperCase()); +}; + +/** + * Format a single key part for display. + * Handles _left/_right suffixes and capitalizes names. + * e.g. "shift_left" -> "Left Shift", "option" -> "Option", "space" -> "Space" + */ +const formatKeyPart = (part: string): string => { + const trimmed = part.trim(); + if (!trimmed) return ""; + + if (trimmed.endsWith("_left")) { + const name = trimmed.slice(0, -5); + return `Left ${capitalizeKey(name)}`; + } + if (trimmed.endsWith("_right")) { + const name = trimmed.slice(0, -6); + return `Right ${capitalizeKey(name)}`; + } + + return capitalizeKey(trimmed); +}; + /** * Get display-friendly key combination string for the current OS - * Returns basic plus-separated format with correct platform key names + * Formats raw hotkey strings like "option_left+shift+space" into + * human-readable form like "Left Option + Shift + Space" */ export const formatKeyCombination = ( combination: string, - osType: OSType, + _osType: OSType, ): string => { - // Simply return the combination as-is since getKeyName already provides - // the correct platform-specific key names - return combination; + if (!combination) return ""; + return combination.split("+").map(formatKeyPart).join(" + "); }; /**