Skip to content

fix(nsh): preserve pending IME composition across Escape under focus fence - #6710

Merged
M4n5ter merged 1 commit into
rust-previewfrom
fix/macos-pending-composition-focus
Nov 9, 2026
Merged

M4n5ter merged 1 commit into
rust-previewfrom
fix/macos-pending-composition-focus

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 9, 2026

Copy link
Copy Markdown
Member

Summary

Refs #6705

When an <Input> or <RichEditor> mounts with autoFocus, its initial EventKind::Focus arms the native focus fence (FOCUS.pending) until the engine thread catches up. If TerminalSurface::apply_composition(..., active: true) (or Win32 WM_IME_COMPOSITION) arrives before EventKind::Focus settles, the active composition entry is queued in FOCUS.pending rather than immediately marking the live editor.

Previously, composing_focused in nsh-platform-macos and composing_focused / terminal_is_composing in nsh-platform-windows only inspected live editor state. A plain Escape keystroke arriving behind the queued composition therefore saw !composing_focused(surface), called disarm(surface) (dropping the queued composition), and blurred the focused editor.

  • Check unsettled composition entries in FOCUS.pending inside composing_focused when !is_replaying(surface) on both macOS and Windows, while reading live editor state during flush_pending replay so queued Enter/Escape keys observe the exact composition state at their position in the FIFO stream.
  • Unify Windows terminal_is_composing and terminal VK_RETURN / VK_ESCAPE composition gating onto composing_focused with replay tracking (replaying).
  • Cover both the unsettled autoFocus focus-fence composition path and the settled commit == preedit NSTextView composition path in rich_editor_composition_commit_matches_preedit, plus a Windows unit test (unsettled_terminal_composition_survives_enter_and_escape).

Verification

  • cargo nextest run --manifest-path third-party/nsh/Cargo.toml -p nsh-terminal
  • Verified both TSX test fixtures (ImeEditor.tsx and UnsettledTerminalIme.tsx) compile via nsh_bundler and settle cleanly in QuickJS (nsh_engine + nsh_base)
  • node scripts/ci.mjs check format
  • node scripts/ci.mjs check licenses
  • node scripts/ci.mjs run tooling (265 passed, 0 failed; macOS AppKit and Windows Win32 native suites run in GitHub Actions native-macos and native-windows)

AI use

Select exactly one:

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

Tool(s) and scope: Antigravity diagnosed the post-merge native-macos terminal_native failure, implemented the composing_focused pending-fence fix across macOS and Windows, and added regression coverage.

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

…fence

Check unsettled FOCUS.pending composition entries in composing_focused (when not replaying) across macOS and Windows so plain Escape during an in-flight focus fence does not disarm queued composition or blur the editor.

Generated-by: Antigravity
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Nov 9, 2026
@M4n5ter
M4n5ter merged commit 033e1a5 into rust-preview Nov 9, 2026
18 of 19 checks passed
@M4n5ter
M4n5ter deleted the fix/macos-pending-composition-focus branch November 9, 2026 04:35

@Astro-Han Astro-Han left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all three changed files at 671ccd4acccd3747233a9e43d391afee2b698257 against rust-preview 1579a9e5fe0d492262808fce523264a33ade0afb; an actual merge succeeds. This PR was merged by another contributor while I was reviewing it, as 033e1a50bd53c38da89bdbda545fb30414cb9ebd. All three reviewed file blobs match that merge, and the actual merge tree against 1579a9e5 matches the landed tree. The four additional code-mode files come from the incoming base and are outside this review. I found no confirmed P0–P2 issue in this change.

The failure premise is supported by the existing source and CI logs. The incoming macOS test fails when committing composition after Enter/Escape while focus is unsettled. The old composing_focused only reads live editor state, whereas the initial composition can still be queued. The Escape paths can then clear that queue. The change makes a pending composition visible for the current node and focus generation. During FIFO replay, both platforms instead read live state, so a later queued commit cannot affect an earlier key. I checked the composition admission, Escape handling and replay callers, including Windows' native IME entries and the new guards against requeuing replayed operations.

For a controlled check, I extracted the exact production composing_focused, is_replaying and with_replaying functions from both platforms and compiled them with small stand-ins for native editors and focus state. All 24 behavioral assertions pass: queued start/end, latest matching entry, stale node/generation, absent focus, live marked text, Windows IME entries, FIFO visibility and nested replay restoration. Replacing only the composition query with its incoming-base implementation produces five failures; disabling replay isolation produces six. The extracted functions also compile with the terminal feature disabled. These checks exercise the query and replay flag logic, not AppKit, Win32 or a complete native input loop.

The macOS regression now checks both the initial focus-fence sequence and a settled editor's equal preedit/commit, with composition-state observation and replacement shortcuts. The Windows regression explicitly asserts the engine is behind before queuing composition and Enter/Escape. I read those tests; I have not executed either native test locally. The author's fixture/compiler and tooling results remain the author's results.

I have now read the macOS job: all 107 platform library tests, all 10 native terminal tests and all 22 Desktop tests pass. The previously failing composition regression passes in 0.396 seconds; Desktop tests finish in 172.540 seconds, including steering in 10.453 seconds. This verifies that regression on macOS. The job remains red because the second pixel test fails while loading its fixture: products/maka/terminal-shell/src/terminal/pixels/tests.rs:63 binds mod+h, which the unchanged macOS keymap rejects as the app-hide shortcut. That fixture and reservation predate this PR and are unchanged in its incoming base. The first pixel test passes; the second fails at line 134 in 0.227 seconds. The Windows job has now completed successfully: all 225 platform tests pass with one skipped, including the new unsettled_terminal_composition_survives_enter_and_escape regression (0.094 seconds). All 22 Desktop tests pass in 283.824 seconds, and both pixel tests pass in 1.186 seconds. The original composition issue therefore has passing native regression evidence on both macOS and Windows. The overall run has completed with failure because of the separate macOS pixel-fixture error above. There is no database schema or protocol change.


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.

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

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants