Repository navigation
fix(nsh): preserve pending IME composition across Escape under focus fence - #6710
Conversation
…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
There was a problem hiding this comment.
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.
Summary
Refs #6705
When an
<Input>or<RichEditor>mounts withautoFocus, its initialEventKind::Focusarms the native focus fence (FOCUS.pending) until the engine thread catches up. IfTerminalSurface::apply_composition(..., active: true)(or Win32WM_IME_COMPOSITION) arrives beforeEventKind::Focussettles, the active composition entry is queued inFOCUS.pendingrather than immediately marking the live editor.Previously,
composing_focusedinnsh-platform-macosandcomposing_focused/terminal_is_composinginnsh-platform-windowsonly inspected live editor state. A plainEscapekeystroke arriving behind the queued composition therefore saw!composing_focused(surface), calleddisarm(surface)(dropping the queued composition), and blurred the focused editor.FOCUS.pendinginsidecomposing_focusedwhen!is_replaying(surface)on both macOS and Windows, while reading live editor state duringflush_pendingreplay so queuedEnter/Escapekeys observe the exact composition state at their position in the FIFO stream.terminal_is_composingand terminalVK_RETURN/VK_ESCAPEcomposition gating ontocomposing_focusedwith replay tracking (replaying).autoFocusfocus-fence composition path and the settledcommit == preeditNSTextViewcomposition path inrich_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-terminalImeEditor.tsxandUnsettledTerminalIme.tsx) compile viansh_bundlerand settle cleanly in QuickJS (nsh_engine+nsh_base)node scripts/ci.mjs check formatnode scripts/ci.mjs check licensesnode scripts/ci.mjs run tooling(265 passed, 0 failed; macOS AppKit and Windows Win32 native suites run in GitHub Actionsnative-macosandnative-windows)AI use
Select exactly one:
Tool(s) and scope: Antigravity diagnosed the post-merge
native-macosterminal_nativefailure, implemented thecomposing_focusedpending-fence fix across macOS and Windows, and added regression coverage.Checklist
Does this PR entail a change in behavior?