Repository navigation
fix(chat): keep a touch text selection where the reader put it - #19864
Conversation
On a phone, selecting transcript text failed three ways: - a handle dragged under the composer dock, the chat header or the phone top bar (which hosts the session title) landed in their text, and the selection took everything in between; - scrolling with a selection unmounted the row holding its start, and the browser re-rooted the start at the top of the transcript; - a start row re-rendered while scrolled away left the start parked between rows, walked up to offset 0 as rows mounted above it. (The fourth case from the original PR, a long-press opening the bubble context menu, is already fixed on main by #18340 and is dropped here.) Fix: - make the header, the dock and the shell top bar inert while a transcript selection is held (touch only); - add retainRange to the virtualizer: every window write keeps the selection's rows mounted; - remember each endpoint as row + character offset, and put an endpoint that leaves its row back where it last sat. A fresh long-press, with no settled position yet, is never rewritten. Replaces #18491. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: cixuuz <26782336+cixuuz@users.noreply.github.com>
ChatPage now calls retainRange on selectionchange; this test landed on main (#18303) after the original PR, and its useVirtualChat mock lacked the new member.
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Check on a real phone that the first tap on the composer or the header still works while a selection is held. iOS has not been tested. [UX-REVIEWED] 2101439 Description read[DESCRIPTION-READ] 968e91977c65afd4217103160f0c7e51986ffed02ca5f2365f52faaf9a996dca That sha256 names everything this verdict read: the PR description, plus the 5 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check on iOS Safari before merge. The inert overlays and the restore run on every touch device, but they were only verified on Android Chrome. What this change shipsInventory (6 items) — 6 justifiedIntent: On a phone, keep a text selection in the chat transcript where the reader put it, instead of letting it jump to the title or the whole chat. This is a FIX (#19858).
[FIRST-PRINCIPLES-REVIEWED] 2101439 Description read[DESCRIPTION-READ] 90066edd4a70ce6506cf5b36397bb625911bceb3c78c6f69f9307f95f3026fd3 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The retained range widens every window write, including far jumps, with no cap, and it runs on desktop too. Watch
[DESIGN-REVIEWED] 2101439 Description read[DESCRIPTION-READ] a9dc5f1f16ccc582dd4c760876cc96e65894b9abb43e87b206563e99af92850a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings block the merge; one advisory finding. FINDING — website/src/hooks/virtualizer/windowRange.ts:126 — when older history is prepended, [OPUS-REVIEWED] 2101439 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
@iamwhatever thanks. Before I approve: this PR commits a stray screenshot, Posted by an AI assistant at bolichen97's request. |
Problem / Motivation
Goal: On a phone, selecting text in a chat transcript keeps the selection where the reader put it.
Replaces #18491 by @Premshay (same-repo takeover after the fork went idle with a merge conflict; Premshay stays the commit author).
Fixes #19858
On Android Chrome (verified on a real device by the original author), text selection in the transcript fails three ways:
Why it matters
Copying a passage from a reply is a basic action on a phone, and in these cases it either fails or copies the whole conversation instead.
Not a goal
MessageContextMenu.tsxtouch-disable and itsAssistantMessage.quote.test.tsxtest and keeps main's version.What changed (motivation → approach → change)
useSelectionInertOverlays.ts,ChatPage.tsx,App.tsx): the chat header overlay, the composer dock, and the shell<header>carrydata-selection-inert. While a transcript selection is held (either endpoint inside the scroller), touch devices setinerton them, so a dragged handle hit-tests the transcript beneath.user-select: nonedoes not change where the caret lands;inertdoes. A capture-phasetouchstartreleases them at once: Android's selection handles dispatch no touch events, so a finger on the page is the reader reaching for something, and the first tap on the composer or header is never swallowed. The next handle move re-appliesinert.windowRange.ts,types.ts,useVirtualChat.ts): newretainRange(range | null).useWindowStatewraps its setter so every window write keeps the retained rows mounted, whichever owner moved the window. It is cleared on session change.utils/selectionRetention.ts,ChatPage.tsx): onselectionchange, both endpoints on rows set the retained span; an endpoint off any row keeps the last span; a collapsed or outside selection releases it. Each endpoint is also remembered as row index + character offset. When the start drifts off its row while the end is on one, or the end leaves the transcript, that endpoint is put back at its last position, by node if still mounted, else by character offset in the row's current text. A selection that has not yet sat on rows (a fresh long-press) is never rewritten.Conflict resolution against current main:
MessageContextMenu.tsxandAssistantMessage.quote.test.tsxtake main's side (see Not a goal); theChatPage.tsximport and thedocs/feature-map/README.mdrow are merged (main's row plus the newuseSelectionInertOverlays.tsentry);ChatPage.dockClearance.test.tsxkeeps main's two-host assertions and lets the dock root carry the new attribute. A second commit addsretainRangeto theuseVirtualChatmock inChatPage.closedSessionProvider.test.tsx, which landed on main (#18303) after the original PR.Pattern harvest
Not generalizable: the bugs come from how Android Chrome hit-tests selection handles over overlays and re-roots a selection whose anchor row a virtualizer unmounts; the fix is specific to the chat transcript's virtualizer and overlays, with no repo-wide code shape a lint rule could catch.
Backwards compatibility
Compatible:
retainRangeis a new member on theuseVirtualChatreturn; nothing existing changes shape. The touch-only behaviours do not run on desktop.Tests
selectionRetention.test.ts: row-span computation; keep vs release; restoring a start that landed on the title; restoring a start parked between rows after its row re-rendered (by character offset); a fresh long-press left alone; an end over the scroller padding left alone.useSelectionInertOverlays.test.tsx: overlays inert while a transcript selection is held on touch, released after; released at once by a fingertouchstartand re-applied by the next selection change; untouched for an outside selection and on desktop.ChatPage.overlaySelection.test.tsx: source contracts for the inert markers, the retained-range wiring, and that only a settled selection is restored.useVirtualChat.surfaceContract.test.tsx:retainRangeadded to the return surface.Local runs on this branch:
tsc -p tsconfig.app.jsonclean.src/test/ChatPage*+src/test/App*: 195 files, 2254 tests pass (after the mock fix).Manual verification
By the original author, on Android Chrome against a live dashboard: dragging a handle over the composer, the header, or the title stays in the transcript; long-pressing a word, scrolling it off screen, and extending the end handle keeps the selection starting at that word (copy confirms). Not verified on iOS.
Screenshots / video
From #18491 (Android, 390×844, dark theme). The still shows a long-press selection with the bubble's action row visible:
touch-selection-18491.webm