fix(ui): preserve composer caret when changing thinking level - #4836
fix(ui): preserve composer caret when changing thinking level#4836seekskyworld wants to merge 1 commit into
Conversation
Capture the active draft selection before the thinking-level menu takes focus and restore it after the setting update when the draft is unchanged. Add a focused regression covering a mid-draft caret. Generated-by: OpenAI Codex Signed-off-by: seekskyworld <djh1813553759@gmail.com>
Astro-Han
left a comment
There was a problem hiding this comment.
Reviewed current head 3eed08bf52b67ee26ff74f8aa31cf3fc575d1686 (OPEN, MERGEABLE/BLOCKED awaiting human review). NO-GO — one P2 below. Checks green on this head (test, label).
P2 — stale caret snapshot survives menu cancel/disabled-selector paths and yanks the cursor back
thinkingSelectionRef (composer.tsx:518-560,562-579) is retained when the menu is Escape/light-dismissed, or when a disabled selector fires pointerdown without onChange. Returning to the editor by keyboard and moving the caret does not trigger the current cleanup; on the next thinking-level pick, rememberThinkingSelection() sees the existing snapshot and skips re-capture, and the rAF restores the old Range — jumping the user's cursor back to a stale position. Same draft value cannot detect a caret-only change. Fix: clear the snapshot on editor focusin and on menu cancel/close paths, and bind it to a draft key or generation.
Scope and limits
Checked the capture-phase Range clone and draft serialization, value/node validity checks, the single rAF restore, call sites at composer.tsx:2193-2205, selector/close behavior in chat-model-switcher.tsx:164-223, and the desktop async settings path. No other P0–P3; no schema/migration. Verified: core build, UI typecheck/build, full UI dist suite, 5 targeted caret tests, Biome, ASF headers, git diff --check. No real Electron/visual smoke run.
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.
简体中文
本条结论全部来自 @Luna-Deep-Qronos 的审查。我自己没有读这份 diff;我核的是当前 head 有没有漂移。当前 head 是 3eed08b,未关闭。一条 P2:旧光标快照在取消路径下不清,下次切档会把光标跳回去。修好再合。
Summary
Changing the thinking level can move an in-progress composer caret to the start of the draft after the selector takes focus. This change snapshots the active contenteditable selection before thinking-level interaction and restores it after the setting update when the draft is unchanged. It preserves the user's caret or selection without applying stale positions to a replaced draft.
Fixes #4827
Verification
node --test packages/ui/dist/__tests__/composer-draft-caret-focus.test.js(5/5 passed)npx biome check packages/ui/src/composer.tsx packages/ui/src/__tests__/composer-draft-caret-focus.test.tsxnpm run check:asf-headersgit diff --checkAI use
Tool(s) and scope: OpenAI Codex authored the implementation and regression test under the requested issue scope.
Checklist
Does this PR entail a change in behavior?