Skip to content

fix(ui): preserve composer caret when changing thinking level - #4836

Open
seekskyworld wants to merge 1 commit into
apache:mainfrom
seekskyworld:fix/4827-thinking-level-caret
Open

fix(ui): preserve composer caret when changing thinking level#4836
seekskyworld wants to merge 1 commit into
apache:mainfrom
seekskyworld:fix/4827-thinking-level-caret

Conversation

@seekskyworld

Copy link
Copy Markdown
Contributor

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.tsx
  • npm run check:asf-headers
  • git diff --check
  • Workspace UI typecheck remains blocked by pre-existing locale and dependency drift errors outside this change; the modified files introduce no typecheck diagnostics.

AI use

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

Tool(s) and scope: OpenAI Codex authored the implementation and regression test under the requested issue scope.

Checklist

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

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

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>
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 5, 2026

@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.

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:旧光标快照在取消路径下不清,下次切档会把光标跳回去。修好再合。

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.

bug(desktop): changing thinking level moves the composer caret to the start

2 participants