(options: ControlKeysOptions)
| 21 | } |
| 22 | |
| 23 | export function handleControlKeys(options: ControlKeysOptions): boolean { |
| 24 | const { |
| 25 | input, |
| 26 | key, |
| 27 | exit, |
| 28 | showSlashCommands, |
| 29 | showFileSearch, |
| 30 | cycleModes, |
| 31 | clearInput, |
| 32 | textBuffer, |
| 33 | onTextBufferUpdate, |
| 34 | } = options; |
| 35 | |
| 36 | // Handle Ctrl+C with two-stage exit, Ctrl+D immediately exits |
| 37 | if (key.ctrl && input === "c") { |
| 38 | // Clear input box if clearInput function is provided |
| 39 | if (clearInput) { |
| 40 | clearInput(); |
| 41 | } |
| 42 | // Let the main process SIGINT handler handle Ctrl+C logic |
| 43 | process.kill(process.pid, "SIGINT"); |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | // Handle Ctrl+V for clipboard paste (including images) |
| 48 | // Note: Cmd+V often doesn't work for image pasting as terminals don't send the key event |
| 49 | if (key.ctrl && input === "v" && textBuffer) { |
| 50 | logger.debug("Handling Ctrl+V clipboard paste"); |
| 51 | |
| 52 | // Check clipboard for images immediately on paste event |
| 53 | checkClipboardForImage() |
| 54 | .then(async (hasImage) => { |
| 55 | if (hasImage) { |
| 56 | logger.debug("Image found in clipboard during paste event"); |
| 57 | const imageBuffer = await getClipboardImage(); |
| 58 | if (imageBuffer) { |
| 59 | textBuffer.addImage(imageBuffer); |
| 60 | // Trigger UI update |
| 61 | if (onTextBufferUpdate) { |
| 62 | onTextBufferUpdate(); |
| 63 | } |
| 64 | return; |
| 65 | } |
| 66 | } |
| 67 | // If no image, let normal text paste handling continue |
| 68 | }) |
| 69 | .catch((error) => { |
| 70 | logger.debug("Error checking clipboard for image:", error); |
| 71 | }); |
| 72 | |
| 73 | // Don't consume the event - let normal text paste handling continue |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | // Handle Ctrl+D to exit |
| 78 | if (key.ctrl && input === "d") { |
| 79 | exit(); |
| 80 | import("../../util/exit.js").then(({ gracefulExit }) => gracefulExit(0)); |
no test coverage detected