({ children }: Props)
| 42 | * - Chord support with automatic timeout |
| 43 | */ |
| 44 | export function KeybindingSetup({ children }: Props): React.ReactNode { |
| 45 | const { addNotification, removeNotification } = useNotifications(); |
| 46 | |
| 47 | const handleWarnings = useCallback( |
| 48 | (warnings: KeybindingWarning[], _isReload: boolean) => { |
| 49 | const notificationKey = 'keybinding-config-warning'; |
| 50 | |
| 51 | if (warnings.length === 0) { |
| 52 | removeNotification(notificationKey); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | const errorCount = count(warnings, w => w.severity === 'error'); |
| 57 | const warnCount = count(warnings, w => w.severity === 'warning'); |
| 58 | |
| 59 | let message: string; |
| 60 | if (errorCount > 0 && warnCount > 0) { |
| 61 | message = `Found ${errorCount} keybinding ${plural(errorCount, 'error')} and ${warnCount} ${plural(warnCount, 'warning')}`; |
| 62 | } else if (errorCount > 0) { |
| 63 | message = `Found ${errorCount} keybinding ${plural(errorCount, 'error')}`; |
| 64 | } else { |
| 65 | message = `Found ${warnCount} keybinding ${plural(warnCount, 'warning')}`; |
| 66 | } |
| 67 | message += ' · /doctor for details'; |
| 68 | |
| 69 | addNotification({ |
| 70 | key: notificationKey, |
| 71 | text: message, |
| 72 | color: errorCount > 0 ? 'error' : 'warning', |
| 73 | priority: errorCount > 0 ? 'immediate' : 'high', |
| 74 | timeoutMs: 60000, |
| 75 | }); |
| 76 | }, |
| 77 | [addNotification, removeNotification], |
| 78 | ); |
| 79 | |
| 80 | return ( |
| 81 | <InkKeybindingSetup |
| 82 | loadBindings={loadKeybindingsSyncWithWarnings} |
| 83 | subscribeToChanges={subscribeToKeybindingChanges} |
| 84 | initWatcher={initializeKeybindingWatcher} |
| 85 | onWarnings={handleWarnings} |
| 86 | onDebugLog={logForDebugging} |
| 87 | > |
| 88 | {children} |
| 89 | </InkKeybindingSetup> |
| 90 | ); |
| 91 | } |
nothing calls this directly
no test coverage detected