Skip to content

fix(user-input): atomic chip selection, modifier-key handling, and stale overlay ghost#4902

Open
waleedlatif1 wants to merge 9 commits into
stagingfrom
fix/logo
Open

fix(user-input): atomic chip selection, modifier-key handling, and stale overlay ghost#4902
waleedlatif1 wants to merge 9 commits into
stagingfrom
fix/logo

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Mention chips in the home user input are now atomic under every selection gesture: select-all, drag, Shift+arrows (grow and shrink), Cmd+Shift jumps, and double-click all snap selection edges to chip boundaries instead of collapsing the selection
  • Plain arrow chip-hop no longer swallows Shift/Cmd/Alt/Ctrl arrow combos or IME composition; Cmd/Ctrl shortcuts are no longer blocked when the caret sits at a chip edge
  • Fixed ghost text lingering after Cmd+A + Delete: the mirror overlay was an unnecessary composited scroll container whose stale GPU layer could outlive the clear — it is now pinned inset-0 with overflow-hidden and shares one class source with the textarea so the two layers can't drift

Type of Change

  • Bug fix

Testing

Tested manually (selection matrix: select-all, drag grow/shrink, shift-arrow grow/shrink across chips, cmd+shift jumps, double-click, click-in-chip caret snap). Typecheck and lint pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 7, 2026 7:09pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Jun 7, 2026

PR Summary

Medium Risk
Touches core home chat input editing, selection, and overlay rendering; behavior changes are broad though scoped to the user-input component.

Overview
Refactors the home chat textarea + highlight overlay so one shared scroller clips height (max-h-[30vh] / max-h-[200px]) while the textarea grows to full content height. Shared FIELD_MIRROR_CLASSES keep wrapping aligned; the overlay is inset-0 on the sizer instead of a separately scrollable layer, removing overlayRef, onScroll, and autoResizeTextarea / MAX_CHAT_TEXTAREA_HEIGHT.

Mention chips behave as atomic units across more gestures: expanded handleSelectAdjust (range edges, grow/shrink vs fresh selection, deferred setSelectionRange with direction) plus adoptDomValue when DOM text drifts from React state. Keyboard fixes: plain-arrow chip-hop only (Shift/Cmd/Alt/Ctrl/IME pass through); Cmd+Backspace stays native; typing inside a chip blocked only for real character keys (not Cmd/Ctrl shortcuts); Space no longer treated as “typing” for chip snap.

Reviewed by Cursor Bugbot for commit 31c66fa. Configure here.

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 7, 2026

Greptile Summary

This PR fixes three distinct behavioral bugs in the home chat UserInput: chip selection atomicity under all selection gestures, modifier-key/IME passthrough for arrow and typing handlers, and a stale GPU layer on the mirror overlay that caused ghost text after Cmd+A+Delete.

  • Selection snapping: handleSelectAdjust now tracks the previous selection in lastSelectionRef and uses edge-movement direction to snap both collapsed carets and ranged-selection edges to chip boundaries, covering select-all, Shift+arrows (grow and shrink), drag, and double-click.
  • Modifier key guards: Arrow-hop, single-chip delete, and character-insertion blocks now check shiftKey / metaKey / altKey / ctrlKey / isComposing so Cmd/Ctrl shortcuts, Shift+arrows, and IME composition events pass through unmodified.
  • Overlay layout: The textarea and overlay are now co-children of a single CSS scroll container (SCROLLER_CLASSES). The overlay is absolute inset-0, eliminating JS scroll-sync; FIELD_MIRROR_CLASSES is extracted as a shared constant so the two layers cannot drift typographically.

Confidence Score: 5/5

Safe to merge — the changes are scoped to client-side selection handling and layout for a single input component, with no data model or API surface changes.

The three bug fixes are logically sound: the selection-snap heuristic correctly infers edge direction from lastSelectionRef, the deferred setSelectionRange reads direction at apply time, the modifier-key guards accurately enumerate every passthrough case, and the single-scroller layout eliminates the JS scroll-sync that caused the stale overlay. No correctness issues or regressions were found on any code path examined.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/constants.ts Introduces shared FIELD_MIRROR_CLASSES to keep textarea and overlay in typographic lockstep; removes autoResizeTextarea/MAX_CHAT_TEXTAREA_HEIGHT; adds SCROLLER_CLASSES for the single native-scroll container.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/index.ts Re-exports SCROLLER_CLASSES; drops autoResizeTextarea and MAX_CHAT_TEXTAREA_HEIGHT. Mechanical change, no issues.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Replaces the two-scroll-container (JS-synced) layout with a single scroller wrapping a relative sizer; handleSelectAdjust expanded to snap all selection gesture types atomically; modifier-key and IME-composition guards added; adoptDomValue backstop handles DOM–state drift.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[onSelect / onMouseUp fires] --> B[Read start, end from DOM]
    B --> C[Update lastSelectionRef]
    C --> D{textarea.value === valueRef?}
    D -- No --> E[adoptDomValue → re-render]
    E --> Z[return]
    D -- Yes --> F{start === end?}
    F -- Yes collapsed --> G{inside chip?}
    G -- No --> M[syncMentionState / syncSlashState]
    G -- Yes --> H[snap to nearest chip edge]
    H --> N[setTimeout: setSelectionRange]
    N --> Z2[return — sync runs on re-fire]
    F -- No ranged --> I[findRangeContaining start and end]
    I --> J{singleEdgeMoved?}
    J -- Yes --> K[Shrinking edge → snap inward\nGrowing edge → absorb chip]
    J -- No fresh select --> L[Expand both edges outward]
    K --> O{newStart > newEnd?}
    L --> O
    O -- Yes --> P[Collapse to newEnd]
    O -- No --> Q{newStart or newEnd changed?}
    P --> Q
    Q -- Yes --> N
    Q -- No --> M
    M --> R[return]
Loading

Reviews (5): Last reviewed commit: "refactor(user-input): native co-scroll f..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 1a2e63f. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6997d3e. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7c3e298. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5b02798. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile review

? startRange.end
: startRange.start
: start
newEnd = endRange ? (singleEdgeMoved && end < prev.end ? endRange.start : endRange.end) : end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale selection ref after typing

Medium Severity

lastSelectionRef is only refreshed in handleSelectAdjust on select/mouseup, but caret moves from ordinary typing do not fire those events. The ranged chip snap logic then compares the new selection to a prev from an earlier click or from before submit, so the first Shift+arrow (or similar) grow/shrink after typing can mis-classify the gesture and snap chip edges to the wrong boundary.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 31c66fa. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

1 issue from previous review remains unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 31c66fa. Configure here.

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.

1 participant