Skip to content

[lexical] Bug Fix: Start a new paragraph on iOS Return after a symbol from the #+= keyboard plane - #9745

Merged
potatowagon merged 1 commit into
meta:mainfrom
vjeux:ios-symbols-plane-return
Nov 3, 2026
Merged

potatowagon merged 1 commit into
meta:mainfrom
vjeux:ios-symbols-plane-return

Conversation

@vjeux

@vjeux vjeux commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

On iPhone, pressing Return after a symbol from the software keyboard's #+= plane (%, *, =, #, +, …) inserts a line break instead of starting a new paragraph, so a list item that ends in 10% swallows the next line.

Opening the #+= plane sends a Shift keydown that is identical to a Shift press (key: 'Shift', code: 'ShiftLeft', keyCode: 16, location: 1), and iOS keeps shiftKey set on every symbol until the Shift keyup, which only comes after the Return. The explicit Shift tracking from #9242 keeps isShiftKeyDown while later keydowns carry shiftKey, so that Return is read as Shift+Return. beforeinput is insertParagraph in both cases, so it can't tell them apart.

Recorded in the iOS 26.2 simulator (Mobile Safari), the two sequences differ only in order:

  • #+= plane, %, Return: keydown Shift, keydown % (shiftKey), keyup % (shiftKey), keydown Enter (shiftKey), beforeinput insertParagraph, keyup Enter, keyup Shift.
  • Hardware Shift+Return, or tapping ⇧ then Return: keydown Shift, keydown Enter (shiftKey), beforeinput insertParagraph, keyup Enter, keyup Shift.

Shift now counts only for an Enter pressed right after it: any other keydown clears it. Tapping ⇧ right before Return, a hardware Shift+Return, and repeated Enter with Shift held still insert line breaks. One hardware-keyboard case changes: holding Shift through other keys and then pressing Enter without releasing it now starts a paragraph, because iOS reports that exactly like the symbols plane.

Test plan

Before

The new tests on main:

$ pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts
     × inserts a paragraph after * typed on the symbols plane
     × inserts a paragraph after % typed on the symbols plane
AssertionError: expected [ { text: 'Some words\n', …(1) } ] to deeply equal [ { text: 'Some words', …(1) }, …(1) ]
      Tests  2 failed | 22 passed (24)

After

$ pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts packages/lexical/src/__tests__/unit/IosEnterAcceptanceBoundary.test.ts packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts packages/lexical/src/__tests__/unit/IosDecoratorTap.test.ts packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDown.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDownApple.test.ts
      Tests  60 passed (60)
$ pnpm exec vitest run --project unit
 Test Files  679 passed | 4 skipped (683)
      Tests  29170 passed | 373 expected fail | 136 skipped (29679)

pnpm run tsc, pnpm run tsc-test, pnpm run flow, pnpm run check-changesets, and ESLint and Prettier on the changed files pass.

Simulator check (iPhone 17 Pro simulator, iOS 26.2, Mobile Safari 26.2), in an editor built on Lexical 0.53.1-nightly.20261102.0 with this one-line change applied to its build, typing with the on-screen keys:

  • - Ramp to 10%, Return, then 50%, Return, done: three bullets. Without the change: one bullet with two line breaks.
  • x*, Return, y: two paragraphs. Without the change: one paragraph with a line break.
  • one, ⇧, Return, two: one paragraph with a line break, with and without the change.
  • h, hardware Shift+Return, k: one paragraph with a line break, with and without the change.

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 3, 2026 6:44am UTC
lexical-playground Ready Ready Preview Nov 3, 2026 6:44am UTC

Request Review

@meta-code-review

meta-code-review Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 6:56 AM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 3, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9745

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9745

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9745

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9745

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9745

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9745

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9745

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9745

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9745

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9745

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9745

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9745

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9745

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9745

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9745

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9745

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9745

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9745

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9745

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9745

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9745

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9745

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9745

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9745

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9745

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9745

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9745

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9745

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9745

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9745

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9745

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9745

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9745

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9745

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9745

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9745

commit: 0251787

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. The new rule at packages/lexical/src/LexicalEvents.ts:2048-2050 is easy to follow, the comment above it explains why the #+= plane needs it, and the new cases in IosShiftEnter.test.ts check the resulting paragraphs, so they would catch a regression. Two optional, non-blocking suggestions:

  1. Mention the hardware-keyboard change in the changeset (.changeset/ios-symbols-plane-return.md:7). The PR description says that on a hardware keyboard, pressing Enter while Shift is still held after other keys (for example after typing ?) now starts a paragraph. The changeset only says a hardware Shift+Return still inserts a line break. AGENTS.md and .changeset/README.md ask for a Verify: paragraph on any fix that changes observable behavior, so one more sentence there would let iPad keyboard users find it in the changelog, for example: Holding Shift through other keys on a hardware keyboard and then pressing Enter now starts a paragraph; release and press Shift again right before Enter for a line break.
  2. One simulator run of the fix. The tests replay the recorded event sequences, and the test plan says the fixed build was not run in the simulator or on a device. Saying so follows AGENTS.md, which asks for any platform you could not exercise to be named under ### After. A quick run of 10% and Return in a playground list in the iOS simulator would confirm that the recorded sequence still reaches the new branch.

For reference, two cases stay as they were. Opening the #+= plane and tapping Return before typing a symbol still inserts a line break, because those events match tap-Shift-then-Return. And an app's own KEY_ENTER_COMMAND handler that reads event.shiftKey still sees Shift on that Return, because only the default beforeinput path changes.

Comment thread .changeset/ios-symbols-plane-return.md Outdated

[fix] On iOS, Return after a symbol from the software keyboard's #+= plane (such as `%` or `*`) starts a new paragraph instead of inserting a line break

Verify: with the iOS software keyboard, type `10%` and tap Return; a new paragraph starts. Tapping Shift right before Return, or a hardware Shift+Return, still inserts a line break.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: the PR description notes one more observable change on hardware keyboards, which this paragraph doesn't mention. Pressing Enter while Shift is still held after other keys (for example after typing ?) now starts a paragraph. AGENTS.md asks a behavior-changing fix's Verify: paragraph to say what to test, so consider adding: Holding Shift through other keys on a hardware keyboard and then pressing Enter now starts a paragraph; release and press Shift again right before Enter for a line break.

… from the #+= keyboard plane

## Description

On iPhone, pressing Return after a symbol from the software keyboard's #+= plane (`%`, `*`, `=`, `#`, `+`, …) inserts a line break instead of starting a new paragraph, so a list item that ends in `10%` swallows the next line.

Opening the #+= plane sends a Shift keydown that is identical to a Shift press (`key: 'Shift'`, `code: 'ShiftLeft'`, `keyCode: 16`, `location: 1`), and iOS keeps `shiftKey` set on every symbol until the Shift keyup, which only comes after the Return. The explicit Shift tracking from meta#9242 keeps `isShiftKeyDown` while later keydowns carry `shiftKey`, so that Return is read as Shift+Return. `beforeinput` is `insertParagraph` in both cases, so it can't tell them apart.

Recorded in the iOS 26.2 simulator (Mobile Safari), the two sequences differ only in order:

- #+= plane, `%`, Return: keydown Shift, keydown `%` (shiftKey), keyup `%` (shiftKey), keydown Enter (shiftKey), beforeinput `insertParagraph`, keyup Enter, keyup Shift.
- Hardware Shift+Return, or tapping ⇧ then Return: keydown Shift, keydown Enter (shiftKey), beforeinput `insertParagraph`, keyup Enter, keyup Shift.

Shift now counts only for an Enter pressed right after it: any other keydown clears it. Tapping ⇧ right before Return, a hardware Shift+Return, and repeated Enter with Shift held still insert line breaks. One hardware-keyboard case changes: holding Shift through other keys and then pressing Enter without releasing it now starts a paragraph, because iOS reports that exactly like the symbols plane.

## Test plan

### Before

The new tests on `main`:

```
$ pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts
     × inserts a paragraph after * typed on the symbols plane
     × inserts a paragraph after % typed on the symbols plane
AssertionError: expected [ { text: 'Some words\n', …(1) } ] to deeply equal [ { text: 'Some words', …(1) }, …(1) ]
      Tests  2 failed | 22 passed (24)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts packages/lexical/src/__tests__/unit/IosEnterAcceptanceBoundary.test.ts packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts packages/lexical/src/__tests__/unit/IosDecoratorTap.test.ts packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDown.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDownApple.test.ts
      Tests  60 passed (60)
$ pnpm exec vitest run --project unit
 Test Files  679 passed | 4 skipped (683)
      Tests  29170 passed | 373 expected fail | 136 skipped (29679)
```

`pnpm run tsc`, `pnpm run tsc-test`, `pnpm run flow`, `pnpm run check-changesets`, and ESLint and Prettier on the changed files pass. The unit tests replay the recorded event sequences; the fix was not run on a device or in the simulator.

@meta-code-review meta-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. The rule is easy to follow, the new tests in IosShiftEnter.test.ts replay the recorded #+= sequence and fail without the fix, and the changeset's Verify: paragraph spells out the one hardware-keyboard case that changes. Two optional, non-blocking suggestions:

  1. Modifier order (packages/lexical/src/LexicalEvents.ts:2048-2050). Because only an Enter keydown keeps the Shift state, Shift → Option (or Control) → Enter on an iPad hardware keyboard now starts a paragraph, while Option → Shift → Enter still inserts a line break; both orders gave a line break before. The #+= plane never sends Alt, Control or Meta keydowns, so keeping the state for those keys too (for example ['Enter', 'Alt', 'Control', 'Meta'].includes(event.key)) would keep the fix and make the order irrelevant. A small test would pin it.
  2. One run on iOS. The Test plan says the fix itself was not run on a device or in the simulator. If you get the chance, a quick simulator check on this head of 10% + Return, ⇧ + Return and a hardware Shift+Return, pasted under ### After as the Commits and Pull Requests section of AGENTS.md describes, would confirm the recorded sequences match what Safari sends.

Known and fine as described: opening #+= and pressing Return without typing a symbol still inserts a line break, because that sequence is identical to tapping ⇧ then Return.

inputState.isShiftKeyDown =
event.key === 'Shift' ||
(inputState.isShiftKeyDown && event.shiftKey && event.key !== 'CapsLock');
(inputState.isShiftKeyDown && event.shiftKey && event.key === 'Enter');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: since only Enter keeps the state, Shift → Option/Control → Enter now starts a paragraph while Option/Control → Shift → Enter still inserts a line break. The #+= plane sends no modifier keydowns, so ['Enter', 'Alt', 'Control', 'Meta'].includes(event.key) would keep the fix without the order dependence.

@potatowagon
potatowagon added this pull request to the merge queue Nov 3, 2026
Merged via the queue into meta:main with commit 16a51d3 Nov 3, 2026
57 checks passed
@vjeux
vjeux deleted the ios-symbols-plane-return branch November 3, 2026 08:51
@potatowagon potatowagon mentioned this pull request Dec 2, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — 0251787d Deployed Nov 3, 2026 by vercel[bot]
Preview – lexical-playground — 0251787d Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants