-
Notifications
You must be signed in to change notification settings - Fork 12k
Description
Summary
OpenCode currently lacks a proper copy mode, making it difficult for users to selectively copy text from chat
messages, code blocks, and other content displayed in the viewport. While basic message copying exists (ctrl+x y), users need vim/tmux-like copy mode for precise text selection and copying.
Problem Statement
Current Limitations
- No Keyboard-based Text Selection: Users cannot select text using keyboard only
- Limited Copy Functionality: Only entire message copying is available (
ctrl+x y) - Incompatible with tmux Copy Mode: OpenCode runs as a TUI application but doesn't integrate with tmux's copy
mode - Poor UX for Code Review: Cannot selectively copy code snippets, error messages, or specific parts of
responses - Mouse Dependency: Users must rely on mouse for text selection, which is inefficient in terminal
environments
User Impact
- Developers: Cannot quickly copy code snippets from AI responses
- Power Users: Keyboard-driven workflow is broken when needing to copy text
- Terminal Enthusiasts: Expect vim/tmux-like navigation and selection
- Accessibility: Mouse-dependent selection is not accessible to all users
Why Copy Mode is Essential
1. Terminal Workflow Compatibility
OpenCode is a TUI (Terminal User Interface) application that runs in terminal emulators. Terminal users expect:
- Vim-like navigation and selection
- Keyboard-driven text manipulation
- Integration with existing terminal tools
2. tmux Integration Problem
When OpenCode runs inside tmux:
- tmux's copy mode (
prefix+[) doesn't work properly, it only can select and copy one page that currently visible of opencode.
3. Pager-like Applications Need Copy Mode
OpenCode functions as a pager for chat messages and code:
- Similar to
less,more, orvim - All major pagers have copy/select functionality
- Users expect to be able to select and copy content
4. Developer Productivity
Developers using OpenCode need to:
- Copy code snippets from AI responses
- Select error messages for debugging
- Extract specific parts of long responses
- Maintain keyboard-driven workflow
What Already Exists (✅)
- Selection System:
type selection struct { startX int endX int startY int endY int }
• Mouse-based selection is implemented
• Coordinate tracking works correctly
2. Highlight System:
```go
type highlightInfo struct {
lineStart, lineEnd int
lines map[int][2]int
}
• Viewport has robust highlighting
• Multi-line highlighting supported
• SetHighlights(), HighlightNext(), HighlightPrevious() available
3. Navigation Keymap:
type KeyMap struct {
PageDown, PageUp key.Binding
HalfPageUp, HalfPageDown key.Binding
Down, Up key.Binding
Left, Right key.Binding
}• Vim-like keys already implemented: j/k, h/l, f/b, d/u
• Navigation system is mature
4. Clipboard Integration:
• cmds = append(cmds, app.SetClipboard(lastTextPart.Text))
• app.SetClipboard() function exists
• Toast notification system available