mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-31 06:42:06 +00:00
refactor(ui): extract keyboard utilities and add padding constant
- Create shared `isSubmitEnter()` utility in `ui/src/lib/keyboard.ts` for IME-aware Enter key handling across all input components - Extract magic number 48 to named constant `COLLAPSED_DEBUG_PANEL_CLEARANCE` with explanatory comment (40px panel header + 8px margin) - Update 5 components to use the new utility: - AssistantChat.tsx - ExpandProjectChat.tsx - SpecCreationChat.tsx - FolderBrowser.tsx - TerminalTabs.tsx This follows up on PR #121 which added IME composition checks. The refactoring centralizes the logic for easier maintenance and documents the padding value that prevents Kanban cards from being cut off when the debug panel is collapsed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
38
ui/src/lib/keyboard.ts
Normal file
38
ui/src/lib/keyboard.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Keyboard event utilities
|
||||
*
|
||||
* Helpers for handling keyboard events, particularly for IME-aware input handling.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if an Enter keypress should trigger form submission.
|
||||
*
|
||||
* Returns false during IME composition (e.g., Japanese, Chinese, Korean input)
|
||||
* to prevent accidental submission while selecting characters.
|
||||
*
|
||||
* @param e - The keyboard event from React
|
||||
* @param allowShiftEnter - If true, Shift+Enter returns false (for multiline input)
|
||||
* @returns true if Enter should submit, false if it should be ignored
|
||||
*
|
||||
* @example
|
||||
* // In a chat input (Shift+Enter for newline)
|
||||
* if (isSubmitEnter(e)) {
|
||||
* e.preventDefault()
|
||||
* handleSend()
|
||||
* }
|
||||
*
|
||||
* @example
|
||||
* // In a single-line input (Enter always submits)
|
||||
* if (isSubmitEnter(e, false)) {
|
||||
* handleSubmit()
|
||||
* }
|
||||
*/
|
||||
export function isSubmitEnter(
|
||||
e: React.KeyboardEvent,
|
||||
allowShiftEnter: boolean = true
|
||||
): boolean {
|
||||
if (e.key !== 'Enter') return false
|
||||
if (allowShiftEnter && e.shiftKey) return false
|
||||
if (e.nativeEvent.isComposing) return false
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user