anomalyco / anomalyco/opencode
Caret jumps to end of prompt after inserting an @mention on the session page
@Hona is already working on this.
Since Aug 13, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Description
On the session page with the v2 prompt composer, typing an @ mention mid-text and selecting a suggestion collapses the caret to the end of the prompt instead of keeping it right after the inserted mention.
For example, with the prompt please @src/index.ts fix the bug, placing the caret after please (offset 7), typing @src, and clicking the file suggestion places the caret at offset 21 (end) instead of after the mention (offset 21 is the end here because the mention is at the end; with trailing text like please @src/index.ts fix it, the caret lands at the very end instead of between the mention and fix it).
Steps to reproduce
- Open a session (the bug only reproduces on the session page, not the new-session draft page).
- Type text in the prompt input, then position the caret in the middle of the text.
- Type
@+ a few characters to open the file suggestion popover. - Click a suggestion.
- The caret jumps to the end of the prompt instead of staying after the inserted mention.
Root cause
renderPromptInputV2Editor in packages/session-ui/src/v2/components/prompt-input/index.tsx rebuilds the editor DOM with replaceChildren when the prompt changes outside a local input, and the render effect does not restore the stored cursor position — it collapses the selection to the end. The draft (new-session) page is unaffected because the browser preserves the caret there, but the session page re-renders the editor and loses the position.
Related
- #37037 (caret jumps in prompt input) — related but describes a streaming-output scenario this report does not cover.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.