Skip to content

fix(session-ui): insert dropped file mentions after the first one - #49185

Closed
deepakajay0477 wants to merge 1 commit into
anomalyco:devfrom
deepakajay0477:fix/session-ui-mention-after-first
Closed

deepakajay0477 wants to merge 1 commit into
anomalyco:devfrom
deepakajay0477:fix/session-ui-mention-after-first

Conversation

@deepakajay0477

@deepakajay0477 deepakajay0477 commented Sep 15, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #39705

Type of change

  • Bug fix

What does this PR do?

In the v2 prompt input, dropping files from the file tree inserts @path mentions. The first drop works, but every later drop is silently ignored once the prompt already contains a mention.

Root cause is in packages/session-ui/src/v2/components/prompt-input/store.ts. addMention() searched the entire prompt for the last @ before the cursor (text.slice(0, end).lastIndexOf("@")) and replaced that range via insertMention(). After the first drop, the last @ is the start of the existing mention. insertMention() only rewrites text parts fully covered by the range, so the replacement produced no change and no error. The v1 prompt input inserted at the caret with an anchored /@(\S*)$/ check, which is why it never had this bug.

Changes:

  • addMention() now finds the replace range with a new mentionQueryStart() helper: it looks only inside the text part containing the cursor and only matches an in-progress query anchored at the cursor (/@(\S*)$/). When there is no such query, it inserts at the cursor.
  • insertMention() is hardened: it clamps ranges that partially overlap a text part and falls back to appending the mention with a trailing space, so it can no longer silently no-op.

Typed @ completion keeps the same behavior (the typed query is still replaced by the selected mention).

How did you verify your code works?

  • bun test src/v2/components/prompt-input/store.test.ts in packages/session-ui: 8 pass. Added 3 regression tests; with the fix reverted, 2 of them fail ("adds another mention when the prompt already contains one", "appends a mention when the cursor follows a trailing mention").
  • bun run typecheck in packages/session-ui passes.
  • Live desktop check: patched a local copy of the 1.18.31 build and dropped 8 files/directories in a row into the prompt (including the same image twice) — all 8 mentions inserted. The unpatched build inserts only the first one.

Screenshots / recordings

Not a visual change; behavior fix in mention insertion.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

addMention() searched the whole prompt for the last "@" before the
cursor. Once the prompt contained a mention, that search landed on the
existing mention's "@" and insertMention() could not replace a range
that spans a mention part, so every drop after the first silently
inserted nothing. The search is now scoped to the text part at the
cursor and insertMention() always inserts.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@deepakajay0477

Copy link
Copy Markdown
Author

Extra regression sweep before rolling this out locally:

  • full packages/session-ui test suite: 86 pass / 0 fail
  • packages/app prompt-input tests: 43 pass / 1 fail — the one failure is submit.test.ts failing to import solid-js/web (server build); it fails identically on unmodified dev (checked out HEAD~1 for the two changed files), so it is pre-existing and unrelated
  • full monorepo bun typecheck (pre-push hook): pass

@kvnloo

kvnloo commented Sep 15, 2026

Copy link
Copy Markdown

Why this matters

v2 prompt input silently ignores file drops after the first @ mention — multi-file context never lands (#39705).

Evidence

Tip 4ecb92b (base dev):

  • packages/session-ui/src/v2/components/prompt-input/store.ts — addMention used lastIndexOf("@") on joined text; now mentionQueryStart() (caret-anchored /@(\S*)$/ in the cursor text part, else insert at cursor)
  • insertMention clamps partial ranges
  • store.test.ts — second mention + active query replace (+60)
  • author: session-ui 86/86; CI standards/compliance/duplicates success

Confirms scope — restore v1 caret-anchored behavior. Happy to help land as-is.

Ask (design, light) — prospective

  1. Is silent mention no-op a class of prompt-store range/part bugs, or only this lastIndexOf("@") slip?
  2. For never-again: caret-anchored query helpers on all mention mutations, or a part-aware edit API that can’t target “last @ in joined text”?

@deepakajay0477

Copy link
Copy Markdown
Author

Thanks for the review, I was hit with this bug, I asked DeepSeek v4.1 f to fix it in a sandbox, I tested it several times, I don't know anything deeper ,and the bug was fixed, I hope it helps everyone, I am leaving it to the maintainers hoping it will come as an update, thank you.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode Desktop - Drag and drop fails when dropping multiple files sequentially

3 participants