Skip to content

Composer @ completion started in whitespace can dismiss early and insert with wrong spacing #291

@mwolson

Description

@mwolson

Summary

Composer @ completion can misbehave when it is started inside existing whitespace.

If the cursor is positioned so there is a space immediately before it and also a space at the cursor position, typing @ opens the completion menu correctly, but follow-up typing and selection can behave incorrectly.

Repro steps

  1. In the composer, insert a file mention so there is already at least one mention pill in the prompt, for example @AGENTS.md.
  2. Continue typing normal text and leave two spaces somewhere later in the prompt.
  3. Move the cursor into that double-space gap so there is one space before the cursor and one space at the cursor position.
  4. Type @.
  5. Type one or two more characters so the menu filters to matching results.
  6. Select a completion.

Expected

  • The completion menu stays open while the typed query still matches results.
  • Selecting a completion replaces the query cleanly.
  • The inserted mention ends with exactly one trailing space.
  • The caret lands immediately after the inserted mention.

Actual

  • In this whitespace-started case, the menu can dismiss while typing even though there is still a valid match.
  • If selection succeeds, the inserted completion can leave an extra trailing space.
  • In related cursor positions, the caret can land farther right than expected after insertion.

Sample setup prompt

Use this to create the setup quickly, then move the cursor back into the double space after then:

Please inspect @AGENTS.md and then summarize how the composer mention picker behaves.

Sample agent prompt

Investigate and fix composer @-completion behavior in the web app.

Problem summary:

  • The composer has mention pills for completed @path references.
  • Cursor handling currently mixes collapsed mention-aware offsets and expanded text offsets.
  • A remaining bug shows up when the user starts an @ completion inside existing whitespace.

Repro target:

  1. In the composer, create at least one existing mention pill, for example @AGENTS.md.
  2. Leave two spaces somewhere later in the prompt.
  3. Put the cursor between those two spaces so there is a space immediately before the cursor and also a space at the cursor position.
  4. Type @, then type a few characters so the completion menu stays filtered.
  5. Select a completion.

Expected behavior:

  • The completion menu should remain open while the typed query still matches results.
  • Selecting a completion should replace the query cleanly.
  • The inserted mention should end with exactly one trailing space.
  • The caret should land immediately after that trailing space.

Known implementation context:

  • Mention parsing/cursor logic lives in apps/web/src/composer-logic.ts.
  • Lexical editor integration lives in apps/web/src/components/ComposerPromptEditor.tsx.
  • Trigger detection and replacement flow live in apps/web/src/components/ChatView.tsx.
  • The bug is likely another edge case where live trigger detection or replacement range calculation is using the wrong cursor coordinate system, or is not consuming an existing space under the cursor when inserting a completion.

Constraints:

  • Preserve existing mention pill behavior.
  • Do not regress cases where completion starts next to non-whitespace text.
  • Add focused tests for the whitespace-started completion case and any cursor/spacing regression you fix.
  • Finish by running bun typecheck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions