Skip to content

feat(tui): copy finished mouse drags to the clipboard on macOS - #362

Open
nybrum wants to merge 1 commit into
openJiuwen-ai:mainfrom
nybrum:feat/tui-copy-on-select
Open

nybrum wants to merge 1 commit into
openJiuwen-ai:mainfrom
nybrum:feat/tui-copy-on-select

Conversation

@nybrum

@nybrum nybrum commented Nov 27, 2026 •

Copy link
Copy Markdown

Paired: GitHub #362 ↔ GitCode !257

Summary

  • On macOS, finishing a mouse drag now copies the selected text, on selectable screens and in text editors. The selection stays highlighted.
  • Why: while iCode owns mouse reporting, the terminal has no selection of its own. In a terminal that does not forward Cmd+C to the app (observed with an xterm.js terminal that does not enable the Kitty keyboard protocol), Cmd+C copies nothing.
  • Clicks, keyboard selections and blank selections leave the clipboard alone. A slip over empty cells must not wipe it.
  • Other platforms and browser (serve) sessions are unchanged.
  • The English and Simplified Chinese guides describe the behavior.

Behavior to review

  • This is on by default for every macOS terminal session, with no setting. I can add one if you prefer it to be opt-in or opt-out.
  • It reaches every screen that uses RightClickScreenCopyMixin, including dialogs through BaseDialog.
  • Dragging in a text editor replaces the clipboard. To paste earlier content over a passage, delete the passage first. The guides say so.
  • Double-click and triple-click selections are not copied. Only drags are.
  • The text editor path reads Textual's private TextArea._selecting, and the screen path hooks Screen._watch__selecting. Both need a check on a Textual upgrade.

Validation

  • Local full run on macOS arm64 (scripts/chrys_test.py --full): 41,251 tests passed and 136 skipped; 1,346 architecture tests passed.
  • Ruff lint and format, and ty for macOS, Linux and Windows targets, passed.
  • New tests in tests/app/tui/behaviors/test_copy_on_select.py cover drag, click, keyboard selection, blank drag and the disabled path. The existing right-click test now turns copy-on-drag off, so it asserts the same thing on every platform.
  • Ran the real app in a pseudo-terminal and sent SGR mouse events over the message box, with a stand-in pbcopy: a click and an unfinished drag copied nothing; releasing the drag sent the selected word once to pbcopy and as OSC 52.
  • Manually dragged over the transcript in an xterm.js terminal and pasted the result (before the blank-selection fix).

🤖 Generated with Claude Code

A macOS terminal may keep Cmd+C for itself, and while the TUI owns mouse
reporting the terminal has no selection to copy. In a terminal without the
Kitty keyboard protocol, Cmd+C therefore copies nothing.

Copy the text when a drag ends, on screens and in text editors. Skip blank
selections so a slip over empty cells keeps the clipboard. Other platforms
and browser sessions are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Nov 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@openjiuwen-ci-bot

Copy link
Copy Markdown

Hi @nybrum, thanks for your contribution!

This pull request is currently waiting for the CLA Assistant check to pass before the CI process can continue.

Please follow the signing link shown by CLA Assistant on this PR. If you have already signed the CLA but the check is still failing, please make sure that all email addresses used in your commits are added to and verified on your GitHub account.

After updating your email settings or signing the CLA, please click Recheck in the CLA Assistant comment/check so the status can be refreshed.

Once the CLA Assistant check passes, CI will continue automatically.

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 28cd3a8e6164e110da36630da7c5ec85c0d583d6

变更摘要

本 PR 为 TUI 增加 macOS 下的「拖选即复制」能力:在终端接管鼠标上报(终端自身没有选区)且 Cmd+C 不会转发给应用的情况下,鼠标拖拽结束即把选中文本写入剪贴板,并保持选区高亮。核心实现集中在 right_click_copy.py:新增 copies_on_select() 作为平台判定入口(仅 macOS 且使用宿主机剪贴板时为真),新增 _copy_dragged_text() 对空白选区不写剪贴板,并在 RightClickScreenCopyMixin 中复用 Textual 的选区状态回调挂上复制逻辑;同时为文本编辑器补上鼠标抬起前的复制入口。点击、键盘选区、空白拖选以及非 macOS/浏览器 serve 会话行为保持不变;相应的英文与简体中文指南也一并更新。

主要改动

  • 新增拖选复制的判定与写入函数: 在 src/chrys/app/tui/behaviors/right_click_copy.py 中新增 copies_on_select()(get_platform().is_macos 且 uses_host_clipboard())与 _copy_dragged_text(),后者仅在选中文本非空白时调用 copy_text_to_clipboards,避免拖过空白单元格清空剪贴板。
  • 屏幕层挂接拖拽结束事件: RightClickScreenCopyMixin 新增 _watch__selecting 覆盖与 _on_selection_drag_finished(),在拖拽结束且存在选区时执行复制,使所有使用该 mixin 的界面(含 BaseDialog 类对话框)都具备该行为。
  • 主屏幕复用新的结束回调: screens/main/screen.py 将 _watch__selecting 收窄为仅在新拖拽开始时隐藏引用弹窗,并新增 _on_selection_drag_finished(),先调用 self._chat_selection.finish_drag() 与父类实现,再触发引用提示,保证复制与引用读取的是同一刷新后的选区。
  • 文本编辑器在鼠标抬起前复制: widgets/text_area.py 新增 _on_mouse_up 覆盖,在 TextArea 自身结束拖拽前调用新增的 copy_finished_text_area_drag()(依据 _selecting 与 selected_text 判断),因此编辑器内拖选同样会被复制且保持选中。
  • 测试覆盖与既有用例适配: 新增 tests/app/tui/behaviors/test_copy_on_select.py,覆盖拖选复制、单击、键盘选区、空白拖选及关闭开关等场景;test_right_click_copy.py 中显式将 copies_on_select 置为 False,使原有右键复制用例在各平台断言一致。

@openjiuwen-collaboration-bot

openjiuwen-collaboration-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

head_sha: 28cd3a8e6164e110da36630da7c5ec85c0d583d6

代码审查

✅ 未发现问题

@openjiuwen-collaboration-bot

Copy link
Copy Markdown
Contributor

head_sha: 28cd3a8e6164e110da36630da7c5ec85c0d583d6

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
禁用词扫描 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A
issue关联检查 N/A N/A
pr size检查 N/A N/A

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants