/** * Keyboard Handler for OpenCode Diff Plugin * * Manages keyboard input and emits actions for the TUI diff viewer. * Provides vim-like keybindings for efficient navigation and change management. */ import { EventEmitter } from 'events'; import { PendingChange, LineId } from '../state-manager.js'; /** * Action types that can be triggered by keyboard input */ export type KeyboardAction = 'acceptLine' | 'rejectLine' | 'acceptHunk' | 'rejectHunk' | 'acceptFile' | 'rejectFile' | 'acceptAll' | 'rejectAll' | 'nextLine' | 'prevLine' | 'nextHunk' | 'prevHunk' | 'nextFile' | 'prevFile' | 'scrollUp' | 'scrollDown' | 'pageUp' | 'pageDown' | 'goToTop' | 'goToBottom' | 'toggleHelp' | 'quit' | 'undo' | 'redo'; /** * Keybinding definition */ export interface Keybinding { key: string; action: KeyboardAction; description: string; context?: 'global' | 'navigation' | 'action' | 'file'; } /** * Navigation position in the diff */ export interface NavigationPosition { hunkIndex: number; lineIndex: number; absoluteLine: number; } /** * Default keybindings for the diff viewer */ export declare const DEFAULT_KEYBINDINGS: Keybinding[]; /** * Action event payload */ export interface ActionEvent { action: KeyboardAction; key: string; position?: NavigationPosition; lineId?: LineId; timestamp: number; } /** * KeyboardHandler - Manages keyboard input for the diff viewer * * Emits events for all keyboard actions that can be consumed by * the TUIRenderer and PendingChange to update state. */ export declare class KeyboardHandler extends EventEmitter { private keybindings; private pendingChange; private currentPosition; private actionHistory; private historyIndex; private maxHistorySize; private isProcessingInput; constructor(pendingChange?: PendingChange); /** * Register all default keybindings */ private registerDefaultKeybindings; /** * Set the pending change being viewed */ setPendingChange(change: PendingChange | null): void; /** * Get the current pending change */ getPendingChange(): PendingChange | null; /** * Get current navigation position */ getCurrentPosition(): NavigationPosition; /** * Set current navigation position */ setCurrentPosition(position: Partial): void; /** * Handle a keypress event * @returns true if the key was handled, false otherwise */ handleKey(key: string): boolean; /** * Check if an action is navigation-only (doesn't modify state) */ private isNavigationOnlyAction; /** * Execute the action and update internal state */ private executeAction; /** * Accept the current line */ private acceptCurrentLine; /** * Reject the current line */ private rejectCurrentLine; /** * Accept all lines in the current hunk */ private acceptCurrentHunk; /** * Reject all lines in the current hunk */ private rejectCurrentHunk; /** * Accept all lines in the current file */ private acceptCurrentFile; /** * Reject all lines in the current file */ private rejectCurrentFile; /** * Accept all pending changes across all files */ private acceptAll; /** * Reject all pending changes across all files */ private rejectAll; /** * Get the LineId for the current position */ private getCurrentLineId; /** * Move to the next line */ private moveToNextLine; /** * Move to the previous line */ private moveToPrevLine; /** * Move to the next hunk */ private moveToNextHunk; /** * Move to the previous hunk */ private moveToPrevHunk; /** * Move to the top of the diff */ private moveToTop; /** * Move to the bottom of the diff */ private moveToBottom; /** * Update the absolute line number */ private updateAbsoluteLine; /** * Add an action to the history */ private addToHistory; /** * Undo the last action */ private undoLastAction; /** * Redo the last undone action */ private redoLastAction; /** * Register a custom keybinding */ registerKeybinding(binding: Keybinding): void; /** * Unregister a keybinding */ unregisterKeybinding(key: string): boolean; /** * Get all registered keybindings */ getKeybindings(): Keybinding[]; /** * Get keybindings filtered by context */ getKeybindingsByContext(context: Keybinding['context']): Keybinding[]; /** * Generate help text organized by sections */ generateHelpText(): string; /** * Generate compact help text for footer display */ generateCompactHelpText(): string; /** * Organize keybindings into sections for help display */ private organizeKeybindingsIntoSections; /** * Get action description for a key */ getActionDescription(key: string): string | undefined; /** * Check if a key is registered */ isKeyRegistered(key: string): boolean; /** * Reset the handler state */ reset(): void; /** * Destroy the handler and clean up */ destroy(): void; } export default KeyboardHandler; //# sourceMappingURL=keyboard-handler.d.ts.map