( text: string, cursorPosition: number, onChange: (value: InputValue) => void, )
| 84 | * Reads from clipboard with OpenTUI fallback, then inserts at cursor. |
| 85 | */ |
| 86 | export function createTextPasteHandler( |
| 87 | text: string, |
| 88 | cursorPosition: number, |
| 89 | onChange: (value: InputValue) => void, |
| 90 | ): (eventText?: string) => void { |
| 91 | return (eventText) => { |
| 92 | const rawPaste = eventText || readClipboardText() |
| 93 | if (!rawPaste) return |
| 94 | const pasteText = Bun.stripANSI(rawPaste) |
| 95 | if (!pasteText) return |
| 96 | const { newText, newCursor } = insertTextAtCursor( |
| 97 | text, |
| 98 | cursorPosition, |
| 99 | pasteText, |
| 100 | ) |
| 101 | onChange({ |
| 102 | text: newText, |
| 103 | cursorPosition: newCursor, |
| 104 | lastEditDueToNav: false, |
| 105 | }) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Creates a paste handler that supports both image and text paste. |
no test coverage detected