Repository navigation
[lexical] Bug Fix: Track explicit Shift state for iOS line breaks - #9242
Merged
Merged
Conversation
…eak action for virtual keyboards ## Description iOS virtual keyboards report `shiftKey: true` for both a manual Shift tap and automatic capitalization. Removing Lexical's iOS guard makes Shift+Enter insert a line break, but also breaks ordinary Enter: repeated Enter stops creating paragraphs, Enter at the start of a heading inserts a line break, and Enter cannot exit an empty list item. This ambiguity is documented in w3c/editing#542. Add **Insert → Line Break** to the playground using `INSERT_LINE_BREAK_COMMAND`, and document the same integration for downstream editors. Add unit coverage for explicit insertion and the existing auto-capitalization behavior, plus an E2E test for inserting from the menu and continuing to type. This is a UI workaround for the reported virtual-keyboard limitation; it does not change the interpretation of iOS Shift+Enter. Refs meta#9239. ## Test plan ### Before Replayed the reported iOS keydown/beforeinput sequence on main, then temporarily removed the `!IS_IOS` guard. The shortcut reproduction passed with the guard removed, but the compatibility probes failed: ```text pnpm run test-unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts × inserts another paragraph when iOS auto-shifts after Enter × inserts a paragraph before a heading with auto-shift active (meta#4335) × exits an empty list item with auto-shift active (meta#4266) Test Files 1 failed (1) Tests 3 failed | 2 passed (5) ``` ### After Restored the guard and kept the compatibility cases alongside coverage for explicit line-break insertion: ```text pnpm run test-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 Test Files 3 passed (3) Tests 13 passed (13) ``` `pnpm run tsc`, `pnpm run tsc-test`, ESLint on the changed JavaScript/TypeScript files, and `git diff --check` exited successfully. Prettier on the changed code, CSS, and documentation reported: ```text All matched files use Prettier code style! ``` The added toolbar E2E test could not reach its assertions in this environment: - Chromium: browser download failed with `End of central directory record signature not found`. - WebKit: the browser downloaded, but launch failed with `Host system is missing dependencies to run browsers`. Installing the dependencies failed with `setgroups (1: Operation not permitted)`. - Physical iPhone/iPad and Firefox were not exercised.
…t Shift for iOS line breaks ## Description iOS Enter events set shiftKey for both manual Shift and automatic capitalization. However, manual toggles emit separate Shift key events while automatic capitalization does not. Track those explicit events per editor and snapshot the state when Enter is pressed, so Shift+Enter can insert a line break without interpreting automatically capitalized Enter as a shortcut. Clear the tracked state when modifiers are released, an unshifted key is observed, Caps Lock changes, the root blurs, or the root is replaced. Preserve the captured Enter intent until beforeinput even when Shift has already been released. Clear pending intent when Enter is canceled or a native insertLineBreak consumes it, and stop arming beforeinput intent for Control+O, which is handled immediately. Remove the earlier toolbar workaround and its documentation. The net change against main is confined to lexical core and its unit tests. Refs meta#9239. Evidence for the separate manual-toggle events: alphagov/govuk-frontend#4095 WebKit dispatches these through modifierFlagsDidChangeFrom:to: and shiftKeyStateChangedFromState:toState: in Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm. ## Test plan ### Before Initial regression cases, before adding explicit Shift tracking: ```text pnpm run test-unit packages/lexical/src/__tests__/unit/IosShiftEnter.test.ts × inserts a line break at offset 0 after an explicit Shift keydown × inserts a line break at offset 5 after an explicit Shift keydown × inserts a line break at offset 10 after an explicit Shift keydown × supports repeated Enter while explicit Shift remains active × remembers Enter intent if Shift is released before beforeinput Test Files 1 failed (1) Tests 5 failed | 12 passed (17) ``` ### After Expanded coverage also verifies canceled Enter, native insertLineBreak, Control+O, Shift release and reset, editor isolation, root replacement, automatic capitalization, heading insertion, and list exit. ```text pnpm run test-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/LexicalIosKoreanIME.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDown.test.ts packages/lexical/src/__tests__/unit/LexicalEventsKeyDownApple.test.ts Test Files 6 passed (6) Tests 34 passed (34) ``` Source and test TypeScript checks (`pnpm run tsc` and `pnpm run tsc-test`), ESLint on the three changed core files, and `git diff b0f5225 --check` all exited successfully. Prettier reported: ```text All matched files use Prettier code style! ``` The unit tests replay DOM event sequences in jsdom. Physical iPhone/iPad validation remains outstanding. In particular, the linked iOS 16.4 investigation reports that the symbols-layout toggle can also emit Shift events; that mode needs verification on current iOS. Chromium, Firefox, and WebKit browser tests were not run for this revision; the earlier attempts were blocked by browser download and system dependency installation failures.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
marked this pull request as ready for review
September 26, 2026 18:30
etrepum
requested review from
acywatson,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 26, 2026 18:30
etrepum
enabled auto-merge
September 27, 2026 22:43
trueadm
approved these changes
Sep 27, 2026
Merged
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
…at release, ship it in lexical, add a range view ## Description `scripts/npm/update-changelog.mjs` wrote each release's CHANGELOG.md block from `git log --oneline LATEST_RELEASE...HEAD~1`. It stripped every character outside `[a-zA-Z0-9()\n \-,.#]`, so `[lexical][lexical-html] Breaking Change:` became `lexicallexical-html Breaking Change`, `$insertList` became `insertList`, and `Find & Replace` became `Find Replace`. The `HEAD~1` range dropped the newest commit, and the block had no categories, links or migration notes. This replaces it with the changesets added in the previous commit: - `pnpm run update-changelog` (still called from `postversion` on the `latest` channel) now runs `scripts/changesets/release.mjs`: it validates the pending changesets, prepends a `## vX.Y.Z (date)` block (the heading shape Renovate and Dependabot slice on) with `### Breaking changes`, `### Deprecations`, `### Features`, `### Fixes`, `### Performance`, `### Documentation`, `### Other` (the `chore` category) and `### Contributors`, empty sections omitted, and deletes the consumed changesets. Each bullet is `**packages**: summary (#PR link)` with the entry's details, including `Migration:` code, reproduced verbatim. The PR number comes from the squash-merge subject of the commit that added the changeset; contributors from `@handle` lines, else that commit's author. Text is never filtered and nothing is dropped, since the input is the set of pending files rather than a git range. - The release still picks its own version (Lexical does not run `changeset version`), but `increment-version` refuses a `latest` patch while a `[breaking]` changeset is pending, and `update-changelog` repeats the check. Prereleases (nightly, next, dev) leave changesets pending. - `pnpm run changelog` previews the next block instead of printing `git log`. - `pnpm run changelog:range -- --from X [--to Y] [--breaking] [--json]` prints every entry in (X, Y], oldest first, optionally only breaking changes and deprecations, optionally as JSON for tools and coding agents. - `pnpm run release-notes -- --version X` prints a version's block for the GitHub release, under the hand-written intro. - `lexical` now ships CHANGELOG.md: `prepare-release` copies the root file into `packages/lexical/` (gitignored) and `update-version` adds it to that package's `files`. Every app that uses Lexical installs `lexical`, so `node_modules/lexical/CHANGELOG.md` gives the full history to anyone upgrading from an installed version, offline. - The maintainers guide describes the new release steps. No library runtime code or public API changes. ## Test plan ### Before The output of the old script, as committed in CHANGELOG.md: ``` $ grep -n 'lexicallexical-html\|Find Replace\|fix insertList' CHANGELOG.md 20:- lexicallexical-html Breaking Change honor createDOM overrides in default DOM export (#9231) Bob Ippolito 47:- lexical-playground Bug Fix Fix Find Replace offsets across decorators and slots (#9186) Monier Ayman 49:- lexical-website Documentation Update fix insertList argument in the commands guide (#9188) Sherry ``` ### After ``` $ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts ✓ |scripts-unit| scripts/__tests__/unit/changesets.test.ts (19 tests) 22ms ✓ |scripts-unit| scripts/__tests__/unit/changelog.test.ts (17 tests) 2327ms Test Files 2 passed (2) Tests 36 passed (36) ``` With three temporary example changesets (not committed) in `.changeset/`: ``` $ pnpm run changelog ## v0.53.0 (2026-10-15) ### Breaking changes - **lexical, @lexical/html**: Example: remove `ExampleNode.legacyMethod` Migration: call `$exampleHelper(node)` instead. ```ts // Before node.legacyMethod(); // After $exampleHelper(node); ``` Detect: calls to `.legacyMethod(`. ### Deprecations - **@lexical/table**: Example: deprecate `$exampleTableHelper` Replacement: `$exampleTableHelperFrom`. Removal: no earlier than v0.60.0. ### Fixes - **@lexical/list**: Example: keep `listStyleType` when a list item is split ### Contributors @Example-contributor $ node scripts/changesets/release.mjs --version 0.52.1 Refusing to release 0.52.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/tmp-breaking.md: Example: remove `ExampleNode.legacyMethod` Run the release with the "minor" increment instead. $ node scripts/npm/increment-version.mjs -i patch --channel latest Refusing a patch release: 1 pending [breaking] changeset(s) need a minor release: - .changeset/tmp-breaking.md: Example: remove `ExampleNode.legacyMethod` Run the "Create New Release Branch" workflow with the "minor" increment. ``` The same changesets in a throwaway clone, each committed with a squash-merge style `(#NNNN)` subject, then the step `postversion` runs: ``` $ npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 3 changeset(s). $ git status --short D .changeset/tmp-breaking.md D .changeset/tmp-deprecation.md D .changeset/tmp-fix.md M CHANGELOG.md $ head -32 CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **lexical, @lexical/html**: Example: remove `ExampleNode.legacyMethod` ([#9992](#9992)) Migration: call `$exampleHelper(node)` instead. ... ### Deprecations - **@lexical/table**: Example: deprecate `$exampleTableHelper` ([#9991](#9991)) ... ### Fixes - **@lexical/list**: Example: keep `listStyleType` when a list item is split ([#9990](#9990)) ### Contributors @Example-contributor, Dev Example ## v0.52.0 (2026-09-27) ``` Stock `changeset version` also accepts the config in that clone (all published packages to 0.53.0, `lexical-playground` left at 0.52.0): ``` $ changeset version 🦋 changeset v3.0.3 All files have been updated. Review them and commit at your leisure $ node -e "...lexical, @lexical/yjs, lexical-playground versions" 0.53.0 0.53.0 0.52.0 ``` Range view and release notes on the current CHANGELOG.md (the breaking sections are backfilled in the next commit): ``` $ pnpm run changelog:range -- --from 0.51.0 --breaking No breaking changes or deprecations after 0.51.0. $ pnpm run release-notes -- --version 0.52.0 | head -1 - lexical Bug Fix Track explicit Shift state for iOS line breaks (#9242) Bob Ippolito ``` The `lexical` tarball includes the copied changelog: ``` $ cp CHANGELOG.md packages/lexical/ && (cd packages/lexical && pnpm pack --dry-run) | grep -A3 'Tarball Contents' Tarball Contents CHANGELOG.md LICENSE README.md ``` `pnpm run tsc-scripts`, `pnpm run tsc-test`, ESLint and Prettier pass on the changed files. The release workflows themselves were not run.
vjeux
added a commit
to vjeux/lexical
that referenced
this pull request
Nov 3, 2026
… 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.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Lexical currently ignores Shift+Enter on iOS because automatic capitalization can set
shiftKeyon ordinary Enter events. However, manually toggling Shift produces separate key events that can distinguish it from automatic capitalization.Track explicit Shift state per editor and capture line-break intent when Enter is pressed. This allows Shift+Enter to insert a line break while preserving ordinary Enter behavior, including repeated Enter, paragraph insertion before headings, and exiting empty lists.
Clear stale state on Shift release, unshifted key events, Caps Lock, blur, and root replacement. Preserve captured Enter intent if Shift is released before
beforeinput.It is not a perfect solution, the following quirks remain while in the autocapitalization state:
Closes #9239
Test plan
Additional unit tests added to cover new behavior. Manually tested in the iOS simulator with software keyboard and on a device.