Skip to content

Conversation

@flexiondotorg
Copy link

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

…t selection

Add support for copying and cutting selected text in the input field using
keyboard shortcuts. This enables keyboard-centric workflows for clipboard
operations.

Fixes anomalyco#7516

Changes:
- Add input_copy keybinding (default: Ctrl+Insert)
- Add input_cut keybinding (default: Shift+Delete)
- Implement handlers in prompt component using existing Clipboard API
- Copy works with text selected via Shift+Arrow and other selection keys
- Cut copies text and then deletes the selection

Default keybindings use CUA-standard (Common User Access) shortcuts that:
- Work reliably across all terminal emulators (not intercepted)
- Match industry-standard clipboard operations from IBM/Windows/Office
- Align with existing input_paste default (Shift+Insert)
- Avoid conflicts with terminal native shortcuts (Ctrl+Shift+C/V)

Both actions:
- Check for active selection before operating
- Use existing Clipboard.copy() for cross-platform clipboard access
- Handle errors gracefully with console logging
- Follow the established pattern of input_paste and input_clear

Technical details:
- Uses TextareaRenderable.hasSelection() to detect selections
- Uses TextareaRenderable.getSelectedText() to retrieve selected text
- Uses TextareaRenderable.deleteChar() for cut (deletes selection)
- Prevents default event handling when operations succeed
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add keyboard-based copy/cut for input field selection

1 participant