(rawText: string)
| 1199 | }); |
| 1200 | }, [input, setPastedContents]); |
| 1201 | function onTextPaste(rawText: string) { |
| 1202 | pendingSpaceAfterPillRef.current = false; |
| 1203 | // Clean up pasted text - strip ANSI escape codes and normalize line endings and tabs |
| 1204 | let text = stripAnsi(rawText).replace(/\r/g, '\n').replaceAll('\t', ' '); |
| 1205 | |
| 1206 | // Match typed/auto-suggest: `!cmd` pasted into empty input enters bash mode. |
| 1207 | if (input.length === 0) { |
| 1208 | const pastedMode = getModeFromInput(text); |
| 1209 | if (pastedMode !== 'prompt') { |
| 1210 | onModeChange(pastedMode); |
| 1211 | text = getValueFromInput(text); |
| 1212 | } |
| 1213 | } |
| 1214 | const numLines = getPastedTextRefNumLines(text); |
| 1215 | // Limit the number of lines to show in the input |
| 1216 | // If the overall layout is too high then Ink will repaint |
| 1217 | // the entire terminal. |
| 1218 | // The actual required height is dependent on the content, this |
| 1219 | // is just an estimate. |
| 1220 | const maxLines = Math.min(rows - 10, 2); |
| 1221 | |
| 1222 | // Use special handling for long pasted text (>PASTE_THRESHOLD chars) |
| 1223 | // or if it exceeds the number of lines we want to show |
| 1224 | if (text.length > PASTE_THRESHOLD || numLines > maxLines) { |
| 1225 | const pasteId = nextPasteIdRef.current++; |
| 1226 | const newContent: PastedContent = { |
| 1227 | id: pasteId, |
| 1228 | type: 'text', |
| 1229 | content: text |
| 1230 | }; |
| 1231 | setPastedContents(prev => ({ |
| 1232 | ...prev, |
| 1233 | [pasteId]: newContent |
| 1234 | })); |
| 1235 | insertTextAtCursor(formatPastedTextRef(pasteId, numLines)); |
| 1236 | } else { |
| 1237 | // For shorter pastes, just insert the text normally |
| 1238 | insertTextAtCursor(text); |
| 1239 | } |
| 1240 | } |
| 1241 | const lazySpaceInputFilter = useCallback((input: string, key: Key): string => { |
| 1242 | if (!pendingSpaceAfterPillRef.current) return input; |
| 1243 | pendingSpaceAfterPillRef.current = false; |
nothing calls this directly
no test coverage detected