anomalyco / anomalyco/opencode

Caret jumps to end of prompt after inserting an @mention on the session page

Open
#42,335 0 comments 0 reactions 1 assignee View on GitHub

@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
  1. Open a session (the bug only reproduces on the session page, not the new-session draft page).
  2. Type text in the prompt input, then position the caret in the middle of the text.
  3. Type @ + a few characters to open the file suggestion popover.
  4. Click a suggestion.
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.