iOS: one Return, one line break, even when Safari is late (#582) #583

Closed
kayg wants to merge 0 commits from issue/ios-double-enter into dev
Owner

Fixes #582: on iPhone, one tap on Return sometimes made two line breaks.

Root cause

On iOS, Safari does not tell the page what Return did. It edits the text itself (beforeinput insertLineBreak, then a changed DOM), and CodeMirror reads that back as the Return key and runs the key's command (our list continuation). Because that edit might never come, CodeMirror also sets a 50 ms timer on keydown and, if no edit was seen by then, runs the command anyway (pendingIOSKey in @codemirror/view).

When Safari's own edit comes later than 50 ms (a busy phone: glass, a long note, the main thread doing something else), the command has already made the new bullet, and then Safari's line break lands on top of it as a plain \n. Two returns for one tap: an empty bullet with the caret a line below it. It was not autocorrect or composition: the editor has autocorrect=off, spellcheck=false, autocapitalize=off, and no composition events fire.

Backspace and Delete use the same path, so a late edit deleted two characters for one tap.

Fix

packages/editor/src/input/ios-keys.ts (added to the live editor): when CodeMirror has run a key's command by itself (its made-up keydown, marked synthetic, was handled) and Safari's own edit for that press shows up afterwards, that edit is cancelled with preventDefault on beforeinput. The normal order (Safari's edit first, then the command) is untouched, as is a key with no command and a press from long before (1 s window). Hardware-keyboard Enter on iPad and Mac Safari never produces a made-up key after the edit, so nothing changes there.

Tests

  • packages/editor/test/ios-keys.test.ts (unit, 8 cases): the late and normal event orders, Shift+Return (no command), once-only, Backspace and Delete, other edits, the 1 s window.
  • apps/web/e2e/enter.spec.ts (WebKit only, where CodeMirror takes its iOS path): replays both captured orders against the real editor: quick, late (list item, log line with time range and tag, plain text), Backspace late, Shift+Return quick and late. With the fix taken out the four late cases fail (two line breaks, two characters deleted); with it they pass.
  • Editor and web specs (editor, enter, tree, list-chrome, list-catch-up, day, vim, touch-select, pickers, keyboard, bar-*): chromium-1440, chromium-390, webkit-1440, webkit-390 all pass (one vim test failed once under load in webkit-1440 and passed on its own and in a rerun of the whole vim spec).
  • Editor unit tests 194 passed, tsc clean, svelte-check 0 errors.
  • iPhone simulator, software keyboard, real taps: 35 Returns with the fix, all one line break (details on the issue).

#582

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk

Fixes #582: on iPhone, one tap on Return sometimes made two line breaks. ## Root cause On iOS, Safari does not tell the page what Return did. It edits the text itself (`beforeinput` `insertLineBreak`, then a changed DOM), and CodeMirror reads that back as the Return key and runs the key's command (our list continuation). Because that edit might never come, CodeMirror also sets a **50 ms timer** on `keydown` and, if no edit was seen by then, runs the command anyway (`pendingIOSKey` in `@codemirror/view`). When Safari's own edit comes later than 50 ms (a busy phone: glass, a long note, the main thread doing something else), the command has already made the new bullet, and then Safari's line break lands on top of it as a plain `\n`. Two returns for one tap: an empty bullet with the caret a line below it. It was not autocorrect or composition: the editor has `autocorrect=off`, `spellcheck=false`, `autocapitalize=off`, and no composition events fire. Backspace and Delete use the same path, so a late edit deleted two characters for one tap. ## Fix `packages/editor/src/input/ios-keys.ts` (added to the live editor): when CodeMirror has run a key's command by itself (its made-up `keydown`, marked `synthetic`, was handled) and Safari's own edit for that press shows up afterwards, that edit is cancelled with `preventDefault` on `beforeinput`. The normal order (Safari's edit first, then the command) is untouched, as is a key with no command and a press from long before (1 s window). Hardware-keyboard Enter on iPad and Mac Safari never produces a made-up key after the edit, so nothing changes there. ## Tests - `packages/editor/test/ios-keys.test.ts` (unit, 8 cases): the late and normal event orders, Shift+Return (no command), once-only, Backspace and Delete, other edits, the 1 s window. - `apps/web/e2e/enter.spec.ts` (WebKit only, where CodeMirror takes its iOS path): replays both captured orders against the real editor: quick, late (list item, log line with time range and tag, plain text), Backspace late, Shift+Return quick and late. With the fix taken out the four late cases fail (two line breaks, two characters deleted); with it they pass. - Editor and web specs (editor, enter, tree, list-chrome, list-catch-up, day, vim, touch-select, pickers, keyboard, bar-*): chromium-1440, chromium-390, webkit-1440, webkit-390 all pass (one vim test failed once under load in webkit-1440 and passed on its own and in a rerun of the whole vim spec). - Editor unit tests 194 passed, `tsc` clean, `svelte-check` 0 errors. - iPhone simulator, software keyboard, real taps: 35 Returns with the fix, all one line break (details on the issue). https://git.kayg.org/kayg/calternal/issues/582 🤖 Generated with [Claude Code](https://claude.ai/code) https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Test: Safari's late line break after Return, Backspace and Shift+Return (#582)
Some checks failed
CI / server (pull_request) Successful in 33s
CI / web (pull_request) Failing after 50s
CI / rust (pull_request) Successful in 4m44s
db672532ad
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Author
Owner

Landed in train AD, #586.

Train AD ran the full suite: fmt, clippy, workspace tests (505 passed, 0 failed), the build, svelte-check, and every Playwright project in parallel shards.

Failures, each checked:

  • glass:268 (chromium-1440) passed 5 of 5 when repeated.
  • trash:33 (webkit-1440) passed 5 of 5 when repeated.
  • tooltips:12 (webkit-390) is a known flake that predates this train.
  • swipe-rows:140/177/197 (webkit-390) fail about 1 in 10 here AND on plain dev (1d2d8ce, 2 of 55 failed), so they predate this train and are tracked separately.

Contents:

  • #583: iOS Return no longer inserts two line breaks (#582).
  • #585: block selection shows only the block tint (#397).
Landed in train AD, #586. Train AD ran the full suite: fmt, clippy, workspace tests (505 passed, 0 failed), the build, svelte-check, and every Playwright project in parallel shards. Failures, each checked: - `glass:268` (chromium-1440) passed 5 of 5 when repeated. - `trash:33` (webkit-1440) passed 5 of 5 when repeated. - `tooltips:12` (webkit-390) is a known flake that predates this train. - `swipe-rows:140/177/197` (webkit-390) fail about 1 in 10 here AND on plain dev (1d2d8ce, 2 of 55 failed), so they predate this train and are tracked separately. Contents: - #583: iOS Return no longer inserts two line breaks (#582). - #585: block selection shows only the block tint (#397).
kayg closed this pull request 2026-10-18 17:42:49 +00:00
Some checks failed
CI / server (pull_request) Successful in 33s
CI / web (pull_request) Failing after 50s
CI / rust (pull_request) Successful in 4m44s

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!583
No description provided.