opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add input_copy and input_cut keybindings for keyboard-based text selection

Open flexiondotorg opened this issue 5 days ago • 1 comments

Summary

Adds support for copying and cutting selected text in the OpenCode TUI input field using keyboard shortcuts, enabling fully keyboard-centric clipboard workflows.

Fixes #7516

Changes

  • Add input_copy keybinding (default: Ctrl+Insert)
  • Add input_cut keybinding (default: Shift+Delete)
  • Implement event handlers in prompt component using existing Clipboard API
  • Works with text selected via Shift+Arrow and other keyboard selection methods

Default Keybindings

The feature uses CUA-standard (Common User Access) keybindings:

  • Ctrl+Insert for copy
  • Shift+Delete for cut

Why CUA-standard?

  • Universal compatibility: Works across all terminal emulators (not intercepted like Ctrl+Shift+C/V)
  • Industry standard: From IBM/Windows/Office, familiar to many users
  • Consistent: Aligns with existing input_paste default (Shift+Insert)
  • No conflicts: Avoids terminal native shortcuts

Users can customize these via config if desired.

Implementation Details

  • Uses TextareaRenderable.hasSelection() to detect active selections
  • Uses TextareaRenderable.getSelectedText() to retrieve selected text
  • Uses TextareaRenderable.deleteChar() for cut operation (deletes selection)
  • Graceful error handling with console logging
  • Follows established patterns from input_paste and input_clear

Testing

  • ✅ Type checking passes (all packages)
  • ✅ All tests pass (622/622)
  • ✅ Manual testing: Copy and cut operations work correctly
  • ✅ Edge case: No-op when no text is selected (graceful handling)

Related

  • Issue: #7516
  • Branch: flexiondotorg:input_copy
  • Base: anomalyco:dev

flexiondotorg avatar Jan 09 '26 19:01 flexiondotorg