Skip to content

fix: leaving a list with Enter no longer damages the paragraph below - #860

Merged
MohamedRejeb merged 1 commit into
mainfrom
fix/issue-857-exit-list-paragraph-below
Nov 11, 2026
Merged

MohamedRejeb merged 1 commit into
mainfrom
fix/issue-857-exit-list-paragraph-below

Conversation

@MohamedRejeb

Copy link
Copy Markdown
Owner

Problem

Enter on an empty list item leaves the list. When a paragraph followed the list, that paragraph lost its first character and an extra empty paragraph appeared.

With a bullet "Item", an empty bullet holding the caret and a paragraph "Next line" below, pressing Enter and typing "Typed" exported

<ul><li>Item</li></ul><p><br></p><p>Typed</p><p>ext line</p>

instead of

<ul><li>Item</li></ul><p>Typed</p><p>Next line</p>

A list at the end of the document was not affected, which hid the bug.

Closes #857.

Cause

checkForParagraphs turned the empty item into a plain paragraph and skipped adding a new one, but left the typed newline in the pending text. Dropping the list prefix moved that newline back, so the scan met it a second time, resolved it to the first span of the paragraph below and split that paragraph, removing its first character as if it were the newline.

Fix

  • The exit removes the typed newline from the pending text and steps the caret back with it.
  • Numbered items below the exit restart at 1. They used to keep their old numbers (a "3." right under the exited item) while toHtml() exported them as a list of their own starting at 1.

No public API change.

Tests

New Issue857ExitListAboveParagraphTest (common):

  • leaving a bullet list and a numbered list keeps the paragraph below intact
  • every paragraph below stays intact, and so does another list below
  • the same through the onTextFieldValueChange bridge
  • numbered items right below the exit restart at 1, a list further below keeps its numbers
  • a list at the end of the document still works
  • undo brings the empty item back

The four "keeps intact" cases, the bridge case and the renumbering case were seen failing before the fix.

Test plan

  • ./gradlew :richeditor-compose:desktopTest (1611 tests)
  • ./gradlew apiCheck
  • ./gradlew allTests (CI)
  • Leave a list above a paragraph with a soft keyboard on Android and iOS

Not in this PR

  • Enter typed over the selected text of a styled list item also leaves the list, and the style of the replaced text then lands on a character of the paragraph below. That has a separate cause: the style carried over from a replaced selection is applied to the range from before the edit.

@MohamedRejeb
MohamedRejeb merged commit 3254ff7 into main Nov 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exiting a list with Enter on an empty item corrupts the paragraph below

1 participant