Skip to content

Fix Enter in the article editor not splitting text with edge spaces - #31418

Open
meh7an wants to merge 1 commit into
telegramdesktop:devfrom
meh7an:fix/rich-editor-enter-split-whitespace
Open

meh7an wants to merge 1 commit into
telegramdesktop:devfrom
meh7an:fix/rich-editor-enter-split-whitespace

Conversation

@meh7an

@meh7an meh7an commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

The article editor shows a block's text in its field without the leading and trailing whitespace and puts that whitespace back when the field is committed. activeTextInsertContext() built its before, selected and after parts from the field's text only, so for a block with such whitespace the parts didn't add up to the stored text. Enter in the middle of a paragraph, list item or quote splits the block only when the parts cover its whole text, so instead of splitting it the editor added an empty paragraph below. Other actions that rebuild the text from the same parts, like inserting blocks into it, lost the whitespace as well.

The parts now include the trimmed whitespace, the same way applyFieldTextToState() restores it, so they match the stored text.

Testing

Tested on macOS 27.0, in a Debug build:

  • A paragraph "Hello world " with a trailing space, opened again from another paragraph, and Enter after "Hello": before the change the text stayed whole and an empty paragraph was added below; now it splits into "Hello" and " world".
  • The same in a list item and in a quote with leading or trailing spaces splits them.
  • Enter at the start or the end of a paragraph adds an empty paragraph above or below it, and splitting text without such spaces works as before.

@john-preston

Copy link
Copy Markdown
Member

Restores whitespace for block splitting, but also restores it after the field is emptied. Subsequent structured paste can create unwanted blank paragraphs around the pasted blocks.

@meh7an
meh7an force-pushed the fix/rich-editor-enter-split-whitespace branch from 3c8e9ff to 09d276d Compare October 22, 2026 18:39
@meh7an

meh7an commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Restores whitespace for block splitting, but also restores it after the field is emptied. Subsequent structured paste can create unwanted blank paragraphs around the pasted blocks.

Thanks, fixed. The trimmed edge whitespace is now added to the insert context only while the field has text, the same way it's restored when the field is committed, so pasting blocks into an emptied paragraph doesn't leave blank paragraphs around them anymore.

This branch has not been deployed

No deployments
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.

2 participants