iPhone: a swipe selects the block, not the words (#397) #403

Closed
kayg wants to merge 0 commits from issue/397-ios-swipe into dev
Owner

Fixes #397 (pending kayg's on-device check; the checklist is on the issue).

Root cause (researched, WebKit source): on iOS, the text-selection gestures (loupe, double-tap-drag, long-press) are held back only by touchstart. A touchmove preventDefault stops pans, and stops native gestures that haven't fired yet. Our swipe called preventDefault only at 32px, by which time iOS had already started its own drag-to-select in the editable text. We also never listened for touchcancel. CodeMirror reads each native selection step as a select.pointer change, so the app showed "words selected". Emulated WebKit has none of the iOS gesture recognizers, which is why e2e passed. Details and sources: the plan comment on #397.

Fix (packages/editor/src/blocks):

  • touch.ts: a swipe is claimed on its first quick (<300ms), clearly sideways move past 10px. All later moves are prevented. The block is still only selected at 32px. A hold (long-press selection), a scroll, a drag right after a tap (double-tap-drag) and the left-edge back swipe stay the phone's. A touchcancel during a claimed swipe still selects the block.
  • swipe-hold.ts (new; added by blockChrome): while a swipe is claimed, and until the phone's selection has been quiet for 400ms (3s at most), a selection change from the screen is turned back into the selection we had. While swiping, the content is user-select: none. The next touch lets go.

Tests: 6 new cases in e2e/touch-select.spec.ts: early claim, scroll untouched, hold left alone, double-tap-drag left alone, touchcancel, and a stray native selection during the hold. The last one fails with the hold removed, so it checks the fix. Results are on the issue.

Emulation can't prove the iPhone result. Don't merge before kayg's device check.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Fixes #397 (pending kayg's on-device check; the checklist is on the issue). **Root cause (researched, WebKit source):** on iOS, the text-selection gestures (loupe, double-tap-drag, long-press) are held back only by `touchstart`. A `touchmove` `preventDefault` stops pans, and stops native gestures that haven't fired yet. Our swipe called `preventDefault` only at 32px, by which time iOS had already started its own drag-to-select in the editable text. We also never listened for `touchcancel`. CodeMirror reads each native selection step as a `select.pointer` change, so the app showed "words selected". Emulated WebKit has none of the iOS gesture recognizers, which is why e2e passed. Details and sources: the plan comment on #397. **Fix (packages/editor/src/blocks):** - `touch.ts`: a swipe is claimed on its first quick (<300ms), clearly sideways move past 10px. All later moves are prevented. The block is still only selected at 32px. A hold (long-press selection), a scroll, a drag right after a tap (double-tap-drag) and the left-edge back swipe stay the phone's. A `touchcancel` during a claimed swipe still selects the block. - `swipe-hold.ts` (new; added by `blockChrome`): while a swipe is claimed, and until the phone's selection has been quiet for 400ms (3s at most), a selection change from the screen is turned back into the selection we had. While swiping, the content is `user-select: none`. The next touch lets go. **Tests:** 6 new cases in `e2e/touch-select.spec.ts`: early claim, scroll untouched, hold left alone, double-tap-drag left alone, touchcancel, and a stray native selection during the hold. The last one fails with the hold removed, so it checks the fix. Results are on the issue. Emulation can't prove the iPhone result. Don't merge before kayg's device check. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Block swipe on iPhone: claim the swipe early, hold the block against iOS's own selection (#397)
Some checks failed
CI / server (pull_request) Successful in 26s
CI / rust (pull_request) Successful in 1m55s
CI / web (pull_request) Failing after 49m7s
feac92f680
On iOS a sideways drag over editable text is also the system's text selection.
WebKit lets only touchstart hold back the loupe and double-tap-drag: a prevented
touchmove can stop pans, and can stop a gesture that hasn't fired yet. We called
preventDefault only at 32px and never listened for touchcancel, so iOS won.

- touch.ts: a swipe is claimed on its first quick (<300ms), clearly sideways
  move past 10px. Every move after that is prevented. A hold, a scroll, or a drag
  right after a tap is left to the phone. A touchcancel during a claimed swipe
  still selects the block.
- swipe-hold.ts: while a swipe is claimed, and until the phone's selection has
  been quiet for 400ms (3s at most), a selection change from the screen is
  turned back into the selection we had. Text can't be selected while swiping.
- e2e: an early claim, scroll, hold, double-tap-drag, touchcancel, and a stray
  native selection during the hold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Landed in dev via train k (#441).

Landed in dev via train k (#441).
kayg closed this pull request 2026-10-15 14:34:33 +00:00
Some checks failed
CI / server (pull_request) Successful in 26s
CI / rust (pull_request) Successful in 1m55s
CI / web (pull_request) Failing after 49m7s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!403
No description provided.