| import { useEffect, useRef } from 'react' |
| import { |
| type AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| logEvent, |
| } from '../services/analytics/index.js' |
| import { useOptionalKeybindingContext } from './KeybindingContext.js' |
| import type { KeybindingContextName } from './types.js' |
|
|
| |
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export function useShortcutDisplay( |
| action: string, |
| context: KeybindingContextName, |
| fallback: string, |
| ): string { |
| const keybindingContext = useOptionalKeybindingContext() |
| const resolved = keybindingContext?.getDisplayText(action, context) |
| const isFallback = resolved === undefined |
| const reason = keybindingContext ? 'action_not_found' : 'no_context' |
|
|
| |
| |
| const hasLoggedRef = useRef(false) |
| useEffect(() => { |
| if (isFallback && !hasLoggedRef.current) { |
| hasLoggedRef.current = true |
| logEvent('tengu_keybinding_fallback_used', { |
| action: |
| action as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| context: |
| context as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| fallback: |
| fallback as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| reason: |
| reason as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| }) |
| } |
| }, [isFallback, action, context, fallback, reason]) |
|
|
| return isFallback ? fallback : resolved |
| } |
|
|