Skip to content

fix(ios): reliable touch selection, selection menu taps, and lossy text decoding - #3146

Merged
deadlyjack merged 10 commits into
mainfrom
ajit/ios-touch-menu-fix
Dec 3, 2026
Merged

deadlyjack merged 10 commits into
mainfrom
ajit/ios-touch-menu-fix

Conversation

@deadlyjack

@deadlyjack deadlyjack commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Makes text selection and the touch selection menu reliable on iOS, and fixes a few iOS issues along the way.

Touch pointers WebKit leaves down

WebKit sends pointerdown, then never sends pointerup or pointercancel, when a native gesture takes over a touch (dragging a selection handle, double-tapping a word). The editor kept thinking a finger was down and hid the selection menu until the next touch.

  • New WebTouchEnd watches touches natively without blocking or delaying any gesture. When the last finger lifts, it sends pointercancel to the page and its frames for every touch pointer still held. It waits a short moment first, so a real pointerup that arrives late still wins.
  • The recognizer never puts itself into a failed state. WebKit doesn't reset a failed recognizer while its double-tap recognizer is pending, so it used to miss the second tap.
  • It is installed in both the main and the preview WebViews, and it keeps working if a touch-end is missed.
  • Its script runs in a private content world, so user pages in Preview see no global and get no messages. A child frame registers itself natively when a touch goes down in it, and native code only notifies the main frame and those frames.

Selection menu

  • Menu buttons activate on touchend, with a 100 ms fallback. Removing the menu can no longer swallow the touchend and let WebKit move the caret under the finger. Buttons also accept WebKit's emulated mousedown when a tap never reports pointerup.
  • The menu puts back a selection that WebKit's native text tap moved or cleared behind a press. This lasts at most 1.5 s, is dropped if the press is cancelled, and ends on any tap outside the menu or any key press in the editor. Menu actions that change the selection keep their own result.
  • This tap guard only runs on iOS.
  • Copying on iOS shows a confirmation toast.
  • Insert color only appears when the caret or selection is on a color. It checks the menu's own pane and inserts into that pane, so split panes stay in sync (merged with fix(editor): insert color into the tapped split pane #3149).

Text decoding

FileContents.decode now handles malformed bytes the way Android does: they become U+FFFD instead of the whole decode failing. A UTF-8 BOM is stripped.

Tests and CI

  • Unit tests cover the touch-end bridge, the menu button activation, the tap guard and getColorRange. Native tests cover WebTouchEnd and FileContents.
  • Flaky hosted-simulator tests are more tolerant of a slow first load:
    • PreviewTransferTests retries the initial preview load once.
    • BridgeTestCase waits up to 90 s for the app WebView on a cold start.
  • docs/ios-port.md documents the touch-end and tap-guard behaviour.
  • Version bumped to 1.13.8 (1027).

🤖 Generated with Claude Code

…ture

WebKit delivers pointerdown but never pointerup or pointercancel when a native gesture claims a touch, such as dragging a text selection handle or double-tapping a word, so the editor kept believing a finger was down and hid the selection menu until the next touch. WebTouchEnd now observes touches natively without preventing or delaying any gesture; when the last finger lifts, pages and their frames receive a pointercancel for the touch pointers still held, after a short settle window so a real pointerup that arrives late wins. The recognizer never fails itself, because a failed recognizer is not reset while WebKit's double-tap recognizer is pending, which made it miss the second tap. It is installed in the main and preview WebViews, and it tolerates a missed touch-end instead of silencing itself.

Selection menu buttons now activate on the touch's touchend, with a 100 ms fallback, so removing the menu cannot drop touchend and let WebKit place the caret under the finger, and they accept WebKit's emulated mousedown when a tap never reports pointerup. The menu also restores the selection that WebKit's native text tap moves or clears behind a press, bounded to 1.5 s and dropped when the press is cancelled. Copying on iOS shows a confirmation toast, and the colour action only appears when the caret or selection holds a colour, using the menu's own editor state so split panes no longer disagree.
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

This PR improves iOS touch selection and selection-menu taps.

  • iOS touch endings clear pointers WebKit leaves held.
  • Selection menu taps run without moving the editor caret.
  • iOS shows a toast after copying or cutting text.
  • Insert color appears only for a color in the current pane.
  • iOS file text reads and writes replace data the encoding cannot represent.
  • iOS simulator waits and the app release numbers are updated.

No new actionable issues were found. All three supplied earlier threads are addressed in the current code. They were unnumbered, so no numbered previous-finding entries are included.

Diagram

sequenceDiagram
    participant Touch as Native touch
    participant Bridge as WebTouchEnd
    participant Page as WebView document
    participant Menu as Selection menu
    Touch->>Bridge: Last finger lifts
    Bridge->>Page: Notify touched frames
    Page->>Page: Wait 100 ms
    Page->>Page: Cancel only pointers still held
    Page->>Menu: End stale pointer interaction
Loading

Reviews (5) · Last reviewed commit: "fix: address review findings on touch me..." · Reviewed by Greptile

Comment thread src/cm/touchSelectionMenu.js Resolved
Comment thread src/cm/touchSelectionMenu.js Resolved
The guard that restores the selection after a menu press no longer outlives the press: any tap outside the menu and any key press in the editor clears it, so the following selection change belongs to the editor. A selection-changing menu action keeps its own selection, because the restore is skipped while an action runs. The docs now describe the guard's full lifetime, and tests cover a second press on the menu, an action that changes the selection, and the outside-tap and key-press cases.
@deadlyjack

Copy link
Copy Markdown
Member Author

@greptile

Ajit Kumar added 3 commits December 2, 2026 16:44
Cancel stale touch pointers after native gestures, activate menu buttons on touch end with WebKit fallbacks, and restore selections cleared by iOS native text taps. Gate the tap guard to iOS and keep touched buttons activatable after WebKit cancels the pointer.

Decode malformed text like Android instead of failing and cover the behaviour with tests. Bump the build number to 1027.
@deadlyjack

Copy link
Copy Markdown
Member Author

@greptile

Comment thread src/cm/selectionMenuUtils.ts Resolved
@deadlyjack

Copy link
Copy Markdown
Member Author

@greptile

Ajit Kumar and others added 2 commits December 3, 2026 20:52
Resolve conflicts with #3149: the menu now takes the tapped pane's view,
gates "insert color" on getColorRange(view.state), and passes the view to
insert-color, which reads the range from that view's state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first suite timed out after ~10s while a cold hosted simulator took
about a minute to finish the initial page load. Wait up to 90s instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@deadlyjack deadlyjack changed the title fix(ios): cancel touch pointers WebKit leaves down after a native ges… fix(ios): reliable touch selection, selection menu taps, and lossy text decoding Dec 3, 2026
bajrangCoder

This comment was marked as outdated.

WebTouchEnd's script ran in the page world of every frame, so user pages
in Preview got a window.acodeNativeTouchEnd global and every iframe
received a postMessage on each tap. The script now runs in its own
content world; a child frame registers natively when a touch pointer goes
down in it, and the touch end is evaluated only in the main frame and
those registered frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Share one press tracker across a selection menu's buttons, so a second
  finger on another button cannot run a second action.
- Only restore selection changes WebKit's native tap makes (DOM select
  events); keep, and protect, selections an app or plugin dispatches,
  including from async menu actions.
- Encode text lossily on iOS like Android's Charset.encode, so files
  decoded with U+FFFD can still be saved in legacy charsets.
- Skip a text toast that is already showing or queued, so repeated
  copies no longer pile up "Copied to clipboard" toasts.
- Compile the line colour regex once and stop scanning past the caret in
  getColorRange, which now runs on every menu show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@deadlyjack

Copy link
Copy Markdown
Member Author

@greptile

@deadlyjack
deadlyjack added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit 912db6d Dec 3, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Dec 3, 2026
@deadlyjack
deadlyjack deleted the ajit/ios-touch-menu-fix branch December 4, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants