Skip to content

Call setCursor onTouchEnd when moving between thoughts#4596

Draft
ethan-james wants to merge 4 commits into
cybersemics:mainfrom
ethan-james:4173-bug-setCaretOffset-in-touchend
Draft

Call setCursor onTouchEnd when moving between thoughts#4596
ethan-james wants to merge 4 commits into
cybersemics:mainfrom
ethan-james:4173-bug-setCaretOffset-in-touchend

Conversation

@ethan-james

@ethan-james ethan-james commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes #4173

Rapid taps between thoughts trigger the same type of focus-retargeting on iOS Safari that was implicated in #4291 and #4394. The mouse events arrive on the wrong element, so all of the cursor-management logic sets focus on the wrong element. The only events that arrive on the correct editable are touch events, so it is necessary to manage the cursor from there.

It is also necessary to detect and block mouse events that land on the wrong editable. This is accomplished by storing the last element to receive a touch event, and then calling preventDefault in onMouseDown in order to stop focus on the re-targeted editable.

Lack of test coverage

Copilot was unable to reproduce the bug in BrowserStack. Efforts are documented in #4538. The taps were confirmed to be landing in the correct places, but latency between taps was pretty high, above 750ms. When I instrumented the iPhone and reproduced the bug manually, taps were closer to 250ms apart.

Copilot was able to get the taps closer together by combining them in a single performActions call, but it didn't help to reproduce the bug.

Related note

It was necessary to avoid calling selection.set inside onTouchEnd, as that would swallow subsequent rapid taps entirely. This moves us a bit closer to the future imagined in #4470. It would, however, be nice if this logic would only be invoked for the second (buggy) tap rather than every tap that fits the profile of moving between thoughts with the keyboard open. I'm still mulling that last bit, as well as the new module-level variables that I don't love.

@ethan-james ethan-james self-assigned this Jul 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Vercel preview: https://em-durrx1sse-cybersemics.vercel.app

@ethan-james ethan-james marked this pull request as draft July 10, 2026 19:22
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.

Cannot set caret on adjacent thought within 1 second of tap

1 participant