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

Open
opened 2026-02-16 17:44:33 -05:00 by yindo · 1 comment
Owner

Originally created by @flexiondotorg on GitHub (Jan 9, 2026).

Originally assigned to: @rekram1-node on GitHub.

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

  1. Use mouse to select text (automatically copied)
  2. Use Ctrl+Y to 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 clipboard
  • input_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:

  1. Config Schema: Add keybind definitions to config.ts

  2. Event Handlers: Add handlers in prompt/index.tsx that:

    • 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()
  3. 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+C for copy: Standard terminal copy binding, avoids conflict with input_clear (Ctrl+C)
  • Ctrl+Shift+X for cut: Safe binding that doesn't conflict with leader key patterns

Both are easily customizable via the config file.

Testing Plan

  1. Select text using Shift+Arrow keys
  2. Press Ctrl+Shift+C and verify text is copied to clipboard
  3. Paste elsewhere and verify copied content
  4. Select text and press Ctrl+Shift+X
  5. Verify text is copied to clipboard AND deleted from input
  6. Test with custom keybindings in config file
  7. Verify no conflicts with existing keybindings

Note: I am currently working on a pull request for this feature.

Originally created by @flexiondotorg on GitHub (Jan 9, 2026). Originally assigned to: @rekram1-node on GitHub. ## 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 1. Use mouse to select text (automatically copied) 2. Use `Ctrl+Y` to 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 clipboard - **`input_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`: 1. **Config Schema**: Add keybind definitions to `config.ts` 2. **Event Handlers**: Add handlers in `prompt/index.tsx` that: - 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()` 3. **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+C` for copy: Standard terminal copy binding, avoids conflict with `input_clear` (`Ctrl+C`) - `Ctrl+Shift+X` for cut: Safe binding that doesn't conflict with leader key patterns Both are easily customizable via the config file. ## Testing Plan 1. Select text using `Shift+Arrow` keys 2. Press `Ctrl+Shift+C` and verify text is copied to clipboard 3. Paste elsewhere and verify copied content 4. Select text and press `Ctrl+Shift+X` 5. Verify text is copied to clipboard AND deleted from input 6. Test with custom keybindings in config file 7. Verify no conflicts with existing keybindings --- **Note:** I am currently working on a pull request for this feature.
yindo added the opentui label 2026-02-16 17:44:33 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 9, 2026):

For keybind-related issues, please also check our pinned keybinds documentation: #4997

@github-actions[bot] commented on GitHub (Jan 9, 2026): For keybind-related issues, please also check our pinned keybinds documentation: #4997
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#4548