Skip to content

fix(nsh): leave Copy to the page when the focused editor selects nothing - #6726

Merged
Colafornia merged 1 commit into
apache:rust-previewfrom
Colafornia:fix/macos-session-copy
Nov 9, 2026
Merged

Colafornia merged 1 commit into
apache:rust-previewfrom
Colafornia:fix/macos-session-copy

Conversation

@Colafornia

Copy link
Copy Markdown
Member
English

Summary

With a RichEditor holding keyboard focus and nothing selected, Cmd+C and Cmd+X were consumed by the editor even when the page had selected output (for example, a session's output). Copy did nothing, so the page's selection never reached the clipboard.

A focused text field had the same dead end on macOS: when the field itself had no selection, the Edit menu's Copy was disabled and never copied the page's selection.

The rich editor now registers Mod+C and Mod+X only while it has a selection; with nothing selected, the keys go on to the page's keymap and the platform. The macOS text views fall back to the surface's selection when they have none, and the Edit menu offers Copy then. With a selection, the editor copies its own content as before. The plain Editor keeps its line-wise copy with no selection, and no new configuration or API is added.

Verification

  • cargo test -p nsh-base --test base rich_editor:: — 203 passed, 1 ignored.
  • New case copy_with_nothing_selected_is_left_to_the_page; with the key-table change reverted, claims_key("mod+c") is true and the test fails (checked by ablation).
  • cargo test -p nsh-platform-macos --lib — 102 passed.
  • cargo check -p nsh-platform-macos and cargo clippy -p nsh-base -p nsh-platform-macos -p nsh-testing --all-targets — no new warnings (the existing large_enum_variant and collapsible_if warnings remain).
  • rustfmt --check passes on the touched files.
  • Not run: the macOS host tests (nsh test … --target macos) and the Windows/Linux builds. The macOS copy: fallback, its menu validation, and the child-view surface resolution have no automated test here.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka implemented the change and its test (commit trailer Generated-by: Maka). Codex reviewed it, ran the ablation, and collapsed duplicated key predicates and menu-validation conditions without changing behavior.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No
中文

摘要

RichEditor 持有键盘焦点且没有选区时,即使页面上有选中内容(例如会话输出),Cmd+C 与 Cmd+X 也会被编辑器消费。Copy 什么都不做,页面的选区因此永远进不了剪贴板。

macOS 上聚焦的文本框也有同样的死路:文本框自身没有选区时,Edit 菜单的 Copy 被置灰,不会复制页面的选区。

现在富文本编辑器只在有选区时注册 Mod+C 和 Mod+X;没有选区时,按键继续交给页面的 keymap 和平台处理。macOS 文本视图在自身没有选区时回退到 surface 的选区,Edit 菜单也随之提供 Copy。有选区时,编辑器仍像以前一样复制自身内容。普通 Editor 保持无选区时按行复制的行为,没有新增配置或 API。

验证

  • cargo test -p nsh-base --test base rich_editor:: —— 203 个通过,1 个忽略。
  • 新增用例 copy_with_nothing_selected_is_left_to_the_page;把键表改动回退后,claims_key("mod+c") 为 true,用例失败(已用消融确认)。
  • cargo test -p nsh-platform-macos --lib —— 102 个通过。
  • cargo check -p nsh-platform-macos 与 cargo clippy -p nsh-base -p nsh-platform-macos -p nsh-testing --all-targets —— 无新增 warning(既有的 large_enum_variant、collapsible_if 仍在)。
  • rustfmt --check 在被改文件上通过。
  • 未运行:macOS 宿主测试(nsh test … --target macos)以及 Windows/Linux 构建。macOS 的 copy: 回退、菜单校验和子视图的 surface 解析在这里没有自动化测试。

AI 参与

只选一项:

  • 没有生成式工具做出实质贡献
  • 生成式工具做出了实质贡献

工具与范围:Maka 实现了改动及其测试(提交 trailer 为 Generated-by: Maka)。Codex 做了评审、消融,并在不改变行为的前提下合并了重复的按键判定和菜单校验条件。

检查项

  • 测试覆盖该改动,且移除改动后测试失败
  • 格式、类型检查与受影响的套件在本地通过

这个 PR 是否带来行为变化?

  • 是 —— 已在上方摘要中说明
  • 否

The rich editor bound Mod+C and Mod+X whatever its selection, and the
composer's hidden caret sink holds the keyboard focus while a session is
open. So the key never reached the Edit menu: the editor copied nothing,
and the selection in the session's output — which belongs to the surface,
not to the editor — was never copied.

Bind the two keys only while something is selected, as Escape is bound
only while there is something to collapse, so the key goes on to the
menu. The focused text view's `copy:` then falls back to the surface's
selected output when it has nothing selected itself, and its menu
validation offers the item then too; a view of the surface's own that
has the keyboard focus resolves the surface it belongs to instead of a
dead end.

The plain editor keeps its line-wise copy: with no selection it copies
the line.

Verified: `nsh-base`'s base suite (785 tests) and a new rich-editor case
that fails without the editor change; `cargo clippy` clean on the touched
crates.

Generated-by: Maka
@Colafornia
Colafornia force-pushed the fix/macos-session-copy branch from a735f4b to 0f07c1e Compare November 9, 2026 16:23
@Colafornia
Colafornia merged commit 12971e4 into apache:rust-preview Nov 9, 2026
@Colafornia
Colafornia deleted the fix/macos-session-copy branch November 9, 2026 16:33
@Astro-Han

Astro-Han commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Post-merge review of the six-file change at 0f07c1ebf8505f237f5603155b314c931c6353c5, already landed by another contributor as 12971e440e93af1501872ec8eaf6bd781360ba92. I verified that the two commits have identical complete Git trees. I found no demonstrated P0–P2 issue in the code and headless behavior checked below.

The original failure is supported by the implementation: Rv::copy returns immediately for an empty editor selection, while the old key table still claimed Copy/Cut. The new selection-dependent key registration lets that key continue to another handler. The approach preserves copying and cutting the editor's own nonempty selection. I checked selection revision updates, composition/focus guards and the new Headless::claims_key observation helper. On macOS I traced copy_surface, both native text-view classes and Edit-menu validation, plus keyboard_surface's resolution of a focused child to its owning surface. The plain Editor implementation is unchanged.

I ran the original affected Rust suite locally: 203 passed, one ignored. Two additional tests through the actual headless engine pass: cutting selected text updates both clipboard and document before releasing the empty caret's Copy/Cut bindings; copying 你😀 retains its Unicode text, and collapsing that selection releases those bindings. With only the controller restored from the pre-change baseline, the original new no-selection regression fails because Copy remains claimed. Restoring the final controller makes it pass again. All six final source blobs were then verified against the reviewed commit, with a clean worktree.

These tests establish the shared editor/keymap behavior, not the complete native responder path. I did not run real macOS Copy/Cut menus, secure-field interaction, secondary-window selection, or Windows/Linux desktop clipboard interaction. In particular, the macOS fallback and menu enablement still require native acceptance; the author's macOS checks remain attributed to the author. No database schema or wire contract changes are involved. CI follow-up: both workflow aggregates have now completed with failure (attempt 1). I read their original logs and checked their explicit checkout commits. The PR run 42654338825 used merge commit 07dbf857dbcb9657b08f1979963d22b67260ee1b, whose complete Git tree equals the landed 12971e44 tree. Its macOS and Windows Desktop suites both fail while waiting for the image-gesture draft (observed: Null, 65.755/71.734 seconds); each reaches four passing tests before that failure, leaving 17 unrun. The macOS platform suite and all ten native focus/input tests pass in that PR run. Its CLI shard 2 also fails the same editor-copy/undo/interrupt test after 72.213 seconds, again with the original draft visible (18 passed, one failed, 94 skipped). I read that job's original log and verified its checkout is the same 07dbf857 merge commit.

The landed run 42655921790 checks out 12971e440e93af1501872ec8eaf6bd781360ba92 directly. Its macOS native focus-transition test instead times out after 5.460 seconds (eight pass, one fails, one remains unrun). Windows passes the image-gesture case, then fails waiting for the /goal draft (observed: Null, 81.409 seconds; five Desktop tests pass and 16 remain unrun). Its CLI shard 2 also fails the editor-copy/undo/interrupt test after 67.702 seconds, with the original draft still visible; the shard finishes with 18 passed, one failed and 94 skipped.

For comparison, I read the corresponding original logs from the preceding 09ca38c23ae9d46214c2743e182fe018c6544429 run 42612011937: those cases pass there. The three affected test source files are unchanged by this PR. The native outcomes also differ between two checkouts with identical final trees, so these observations alone do not isolate a PR-caused defect or establish that the failures are harmless. No retries were triggered. Full native acceptance and investigation of these failures remain open; neither landing nor the earlier green baseline validates the current result.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@Colafornia Colafornia self-assigned this Nov 10, 2026
M4n5ter added a commit that referenced this pull request Nov 10, 2026
…hEditor keys static (#6731)

Keep RichEditor's Mod+C and Mod+X bindings static across selection transitions so back-to-back Select All -> Copy bursts and ComposerInput's editor-internal Ctrl+C fallback run deterministically without key-table churn, while routing Copy and Escape to an active surface output selection at the platform boundary on macOS, Windows, and TUI when the focused editor has no native selection of its own.

Refs #6726

Generated-by: Antigravity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants