-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Problem
Currently, the input field supports keyboard-based text selection via Shift+Arrow keys and other input_select_* keybindings, but there is no way to copy or cut the selected text using the keyboard. Users must resort to mouse selection to copy text to the clipboard, which breaks keyboard-centric workflows.
While mouse selection works well and automatically copies to clipboard via OSC52, power users who prefer keyboard navigation have no equivalent functionality.
Current Workarounds
- Use mouse to select text (automatically copied)
- Use
Ctrl+Yto copy console-level selections (but this doesn't work for textarea keyboard selections)
Proposed Solution
Add two new keybindings that work with keyboard-based text selection in the input field:
input_copy(default:Ctrl+Shift+C) - Copy selected text to clipboardinput_cut(default:Ctrl+Shift+X) - Cut selected text to clipboard (copy + delete)
Implementation Details
The implementation follows the established pattern of input_paste and input_clear:
-
Config Schema: Add keybind definitions to
config.ts -
Event Handlers: Add handlers in
prompt/index.tsxthat:- Check for active selection using
input.hasSelection() - Retrieve selected text using
input.getSelectedText() - Copy to clipboard using existing
Clipboard.copy()utility - For cut: delete selection using
input.deleteChar()
- Check for active selection using
-
Key Technical Points:
- Uses TextareaRenderable's public API only
- Leverages existing cross-platform Clipboard utility
- Includes error handling with console logging
- Prevents default event handling when operations succeed
- No breaking changes (new optional keybindings with sensible defaults)
Benefits
- ✅ Enables fully keyboard-centric workflow
- ✅ Follows CUA (Common User Access) standard conventions
- ✅ Consistent with standard text editors (VS Code, Sublime, etc.)
- ✅ No breaking changes (purely additive)
- ✅ Cross-platform compatible (uses existing Clipboard utility)
- ✅ Works with all existing selection keybindings (
Shift+Arrow,Ctrl+Shift+Home, etc.)
Default Keybindings Rationale
Ctrl+Shift+Cfor copy: Standard terminal copy binding, avoids conflict withinput_clear(Ctrl+C)Ctrl+Shift+Xfor cut: Safe binding that doesn't conflict with leader key patterns
Both are easily customizable via the config file.
Testing Plan
- Select text using
Shift+Arrowkeys - Press
Ctrl+Shift+Cand verify text is copied to clipboard - Paste elsewhere and verify copied content
- Select text and press
Ctrl+Shift+X - Verify text is copied to clipboard AND deleted from input
- Test with custom keybindings in config file
- Verify no conflicts with existing keybindings
Note: I am currently working on a pull request for this feature.