Repository navigation
[lexical] Bug Fix: Start a new paragraph on iOS Return after a symbol from the #+= keyboard plane - #9745
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
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:
- 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.mdask for aVerify: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. - 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 of10%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.
|
|
||
| [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. |
There was a problem hiding this comment.
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.
8c49cc8 to
0251787
Compare
There was a problem hiding this comment.
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:
- Modifier order (
packages/lexical/src/LexicalEvents.ts:2048-2050). Because only anEnterkeydown 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 sendsAlt,ControlorMetakeydowns, 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. - 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### Afteras 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'); |
There was a problem hiding this comment.
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.
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 in10%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 keepsshiftKeyset on every symbol until the Shift keyup, which only comes after the Return. The explicit Shift tracking from #9242 keepsisShiftKeyDownwhile later keydowns carryshiftKey, so that Return is read as Shift+Return.beforeinputisinsertParagraphin 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:
%, Return: keydown Shift, keydown%(shiftKey), keyup%(shiftKey), keydown Enter (shiftKey), beforeinputinsertParagraph, keyup Enter, keyup Shift.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:After
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.