Skip to content

feat: Copy Mode for OpenCode #2755

@thuanpham582002

Description

@thuanpham582002

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

  1. No Keyboard-based Text Selection: Users cannot select text using keyboard only
  2. Limited Copy Functionality: Only entire message copying is available (ctrl+x y)
  3. Incompatible with tmux Copy Mode: OpenCode runs as a TUI application but doesn't integrate with tmux's copy
    mode
  4. Poor UX for Code Review: Cannot selectively copy code snippets, error messages, or specific parts of
    responses
  5. 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, or vim
  • 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 (✅)

  1. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions