( action: string, context: KeybindingContextName, fallback: string, )
| 27 | * // Returns the user's configured binding, or 'ctrl+o' as default |
| 28 | */ |
| 29 | export function useShortcutDisplay( |
| 30 | action: string, |
| 31 | context: KeybindingContextName, |
| 32 | fallback: string, |
| 33 | ): string { |
| 34 | const keybindingContext = useOptionalKeybindingContext() |
| 35 | const resolved = keybindingContext?.getDisplayText(action, context) |
| 36 | const isFallback = resolved === undefined |
| 37 | const reason = keybindingContext ? 'action_not_found' : 'no_context' |
| 38 | |
| 39 | // Log fallback usage once per mount (not on every render) to avoid |
| 40 | // flooding analytics with events from frequent re-renders. |
| 41 | const hasLoggedRef = useRef(false) |
| 42 | useEffect(() => { |
| 43 | if (isFallback && !hasLoggedRef.current) { |
| 44 | hasLoggedRef.current = true |
| 45 | logEvent('tengu_keybinding_fallback_used', { |
| 46 | action: |
| 47 | action as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 48 | context: |
| 49 | context as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 50 | fallback: |
| 51 | fallback as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 52 | reason: |
| 53 | reason as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 54 | }) |
| 55 | } |
| 56 | }, [isFallback, action, context, fallback, reason]) |
| 57 | |
| 58 | return isFallback ? fallback : resolved |
| 59 | } |
no test coverage detected