Commit 2322b00
authored
feat: add paste support to InputHandler (#15)
* feat: add paste support to InputHandler
## Problem
Terminal had working copy (auto-copy on selection) but paste was
completely missing. Users couldn't paste text using Ctrl+V, Cmd+V,
or right-click paste.
## Solution
Added complete paste support to InputHandler:
1. **Paste Event Listener**: Listens for browser paste events on container
2. **handlePaste Method**: Extracts clipboard text and sends to terminal
3. **Ctrl+V/Cmd+V Support**: Bypasses normal keydown handling to allow paste
4. **Proper Cleanup**: Removes paste listener on dispose()
## Features
✅ Ctrl+V / Cmd+V keyboard shortcuts
✅ Right-click → Paste (browser context menu)
✅ Multi-line paste support
✅ Empty/null clipboard handling
✅ Focus-aware (only works when terminal focused)
## Tests
Added 6 comprehensive tests:
- Single-line paste
- Multi-line paste
- Empty clipboard handling
- Null clipboard data handling
- Ctrl+V shortcut behavior
- Cmd+V shortcut behavior
All 40 tests passing (6 new + 34 existing)
## Terminal Behavior Notes
- **Copy**: Auto-copy on mouse selection (no Ctrl+C copy)
- **Paste**: Ctrl+V / Cmd+V / Right-click
- **Ctrl+C**: Sends SIGINT (interrupt signal) - standard terminal behavior
This matches behavior of iTerm2, Terminal.app, Windows Terminal, etc.
## Files Changed
- lib/input-handler.ts: Added paste event handling
- lib/input-handler.test.ts: Added mock ClipboardEvent + 6 tests
## Future Enhancements
- Bracketed paste mode (\x1b[200~ ... \x1b[201~)
- Paste confirmation for large text blocks
- Rich text → plain text conversion
- Paste rate limiting
* fix: prevent Cmd+C from outputting 'c' character on Mac
## Problem
When pressing Cmd+C (Command+C on Mac) to copy selected text,
the terminal would output a 'c' character in addition to copying.
This happened because:
1. metaKey (Cmd) wasn't checked in isPrintableCharacter()
2. Cmd+C was being treated as a printable character
3. The 'c' was sent to the terminal output
## Solution
Two-part fix:
1. **Check metaKey in isPrintableCharacter()**
- Added check: `if (event.metaKey) return false;`
- Prevents ANY Cmd+key combo from being treated as printable
2. **Explicit Cmd+C handling**
- Added early return for Cmd+C (similar to Cmd+V)
- Allows SelectionManager to handle copy
- Prevents any character from being sent to terminal
## Behavior
- **Ctrl+C**: Sends interrupt signal (0x03) - standard terminal
- **Cmd+C** (Mac): Triggers copy, no output - Mac standard
- **Selection**: Auto-copies on mouse selection (all platforms)
- **Cmd+V** (Mac): Triggers paste
This matches native Mac terminal behavior where:
- Cmd+C = Copy
- Cmd+V = Paste
- Ctrl+C = Interrupt (SIGINT)
## Tests
Added test: "Cmd+C allows copy (no data sent)"
- Verifies Cmd+C doesn't send any data to terminal
- All 41 tests passing
## Files Changed
- lib/input-handler.ts: Added metaKey check + Cmd+C handling
- lib/input-handler.test.ts: Added Cmd+C test
Fixes #issue (user reported Cmd+C outputting 'c')1 parent 2262634 commit 2322b00
2 files changed
Lines changed: 213 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
23 | 33 | | |
24 | | - | |
25 | | - | |
| 34 | + | |
| 35 | + | |
26 | 36 | | |
27 | 37 | | |
28 | 38 | | |
| |||
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
47 | 77 | | |
48 | 78 | | |
49 | | - | |
| 79 | + | |
| 80 | + | |
50 | 81 | | |
51 | | - | |
| 82 | + | |
52 | 83 | | |
53 | 84 | | |
54 | 85 | | |
55 | | - | |
| 86 | + | |
56 | 87 | | |
57 | 88 | | |
58 | 89 | | |
59 | 90 | | |
60 | 91 | | |
61 | | - | |
| 92 | + | |
62 | 93 | | |
63 | 94 | | |
64 | 95 | | |
| |||
67 | 98 | | |
68 | 99 | | |
69 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
70 | 107 | | |
71 | 108 | | |
72 | 109 | | |
| |||
276 | 313 | | |
277 | 314 | | |
278 | 315 | | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
279 | 331 | | |
280 | 332 | | |
281 | 333 | | |
| |||
610 | 662 | | |
611 | 663 | | |
612 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
613 | 759 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
207 | 208 | | |
208 | 209 | | |
209 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
210 | 214 | | |
211 | 215 | | |
212 | 216 | | |
| |||
244 | 248 | | |
245 | 249 | | |
246 | 250 | | |
247 | | - | |
248 | | - | |
| 251 | + | |
| 252 | + | |
249 | 253 | | |
250 | 254 | | |
| 255 | + | |
251 | 256 | | |
252 | 257 | | |
253 | 258 | | |
| |||
260 | 265 | | |
261 | 266 | | |
262 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
263 | 284 | | |
264 | 285 | | |
265 | 286 | | |
| |||
410 | 431 | | |
411 | 432 | | |
412 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
413 | 467 | | |
414 | 468 | | |
415 | 469 | | |
| |||
426 | 480 | | |
427 | 481 | | |
428 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
429 | 488 | | |
430 | 489 | | |
431 | 490 | | |
| |||
0 commit comments