TUI textarea: Right-click paste not working - missing onContextMenu handler #8279

Open
opened 2026-02-16 18:09:34 -05:00 by yindo · 3 comments
Owner

Originally created by @liyunlong523 on GitHub (Feb 1, 2026).

Originally assigned to: @kommander on GitHub.

描述:
在使用 OpenCode TUI(终端界面)的 prompt 输入框时,无法使用鼠标右键粘贴文本。

位置

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx 中的 <textarea> 组件

问题分析

当前的 textarea 组件只实现了以下事件处理:

  1. Ctrl+V 粘贴(通过 onKeyDown,第 812-832 行)
  2. Bracketed Paste 模式粘贴(通过 onPaste,第 891-958 行)
  3. 鼠标点击 获得焦点(通过 onMouseDown,第 971 行)
    缺少 onContextMenu 事件处理器,导致右键点击时终端的默认上下文菜单行为可能会与 OpenCode 的自定义粘贴处理冲突。

代码引用

<textarea
  // ... 现有的事件处理器 ...
  onPaste={async (event: PasteEvent) => { /* ... */ }}
  onKeyDown={async (e) => { /* ... */ }}
  onMouseDown={(r: MouseEvent) => r.target?.focus()}
  // 缺少: onContextMenu={(e) => e.preventDefault()}
  // ...
/>
重现步骤
1. 在终端中运行 OpenCode TUIoh-my-opencode
2. 将文本复制到剪贴板
3.  prompt 输入框中点击鼠标右键
4. 尝试从右键菜单选择粘贴
期望行为
右键菜单应该正常显示粘贴选项,或者至少不会干扰终端的默认粘贴行为。
实际行为
右键点击可能被忽略,或者菜单行为异常。

建议的修复方案
方案 1:阻止默认右键行为
 <textarea> 组件上添加 onContextMenu 事件处理器来阻止默认行为(如果这是期望的行为):
<textarea
  // ... 其他 props ...
  onContextMenu={(e) => {
    // 根据需求决定是否阻止默认行为
    // e.preventDefault(); 
  }}
/>
方案 2:提供自定义右键菜单支持
如果需要完全自定义的右键菜单体验,可以:
1. 添加 onContextMenu={(e) => e.preventDefault()} 阻止默认菜单
2. 使用 OpenCode 的对话框系统实现自定义上下文菜单(类似于 command palette
3. 提供"粘贴""选择全部""清除"等选项
方案 3:文档化快捷键
 UI 中明确显示粘贴快捷键提示,引导用户使用键盘快捷键:
- Shift+Insert
- Ctrl+Shift+V
- Ctrl+V (部分终端)
环境信息
- OpenCode 版本: 3.x
- 操作系统: Linux
- 终端: 请填写你使用的终端,如 kitty, alacritty, gnome-terminal 
附加信息
- 用户已知的临时解决方案是使用命令面板:Ctrl+X  选择 prompt.paste 命令
- 或者使用终端的键盘快捷键(Shift+Insert, Ctrl+Shift+V
Originally created by @liyunlong523 on GitHub (Feb 1, 2026). Originally assigned to: @kommander on GitHub. 描述: 在使用 OpenCode TUI(终端界面)的 prompt 输入框时,无法使用鼠标右键粘贴文本。 ### 位置 `packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx` 中的 `<textarea>` 组件 ### 问题分析 当前的 `textarea` 组件只实现了以下事件处理: 1. **Ctrl+V** 粘贴(通过 `onKeyDown`,第 812-832 行) 2. **Bracketed Paste** 模式粘贴(通过 `onPaste`,第 891-958 行) 3. **鼠标点击** 获得焦点(通过 `onMouseDown`,第 971 行) 但**缺少 `onContextMenu` 事件处理器**,导致右键点击时终端的默认上下文菜单行为可能会与 OpenCode 的自定义粘贴处理冲突。 ### 代码引用 ```tsx <textarea // ... 现有的事件处理器 ... onPaste={async (event: PasteEvent) => { /* ... */ }} onKeyDown={async (e) => { /* ... */ }} onMouseDown={(r: MouseEvent) => r.target?.focus()} // 缺少: onContextMenu={(e) => e.preventDefault()} // ... /> 重现步骤 1. 在终端中运行 OpenCode TUI(oh-my-opencode) 2. 将文本复制到剪贴板 3. 在 prompt 输入框中点击鼠标右键 4. 尝试从右键菜单选择粘贴 期望行为 右键菜单应该正常显示粘贴选项,或者至少不会干扰终端的默认粘贴行为。 实际行为 右键点击可能被忽略,或者菜单行为异常。 建议的修复方案 方案 1:阻止默认右键行为 在 <textarea> 组件上添加 onContextMenu 事件处理器来阻止默认行为(如果这是期望的行为): <textarea // ... 其他 props ... onContextMenu={(e) => { // 根据需求决定是否阻止默认行为 // e.preventDefault(); }} /> 方案 2:提供自定义右键菜单支持 如果需要完全自定义的右键菜单体验,可以: 1. 添加 onContextMenu={(e) => e.preventDefault()} 阻止默认菜单 2. 使用 OpenCode 的对话框系统实现自定义上下文菜单(类似于 command palette) 3. 提供"粘贴"、"选择全部"、"清除"等选项 方案 3:文档化快捷键 在 UI 中明确显示粘贴快捷键提示,引导用户使用键盘快捷键: - Shift+Insert - Ctrl+Shift+V - Ctrl+V (部分终端) 环境信息 - OpenCode 版本: 3.x - 操作系统: Linux - 终端: 请填写你使用的终端,如 kitty, alacritty, gnome-terminal 等 附加信息 - 用户已知的临时解决方案是使用命令面板:Ctrl+X → 选择 prompt.paste 命令 - 或者使用终端的键盘快捷键(Shift+Insert, Ctrl+Shift+V)
yindo added the opentui label 2026-02-16 18:09:34 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 1, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9922: Windows & Ubuntu: impossible to paste API key after /connect (Ctrl-V / Ctrl-Shift-V / right-click all fail, no hints) - mentions right-click paste failures alongside keyboard shortcut paste methods

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue might be a duplicate of existing issues. Please check: - #9922: Windows & Ubuntu: impossible to paste API key after /connect (Ctrl-V / Ctrl-Shift-V / right-click all fail, no hints) - mentions right-click paste failures alongside keyboard shortcut paste methods Feel free to ignore if none of these address your specific case.
Author
Owner

@github-actions[bot] commented on GitHub (Feb 1, 2026):

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

@github-actions[bot] commented on GitHub (Feb 1, 2026): For keybind-related issues, please also check our pinned keybinds documentation: #4997
Author
Owner

@wzf9 commented on GitHub (Feb 8, 2026):

粘贴点按右键或者shift+insert
复制就是左键选中就直接复制 或 Ctrl + Insert

@wzf9 commented on GitHub (Feb 8, 2026): 粘贴点按右键或者shift+insert 复制就是左键选中就直接复制 或 Ctrl + Insert
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8279