Skip to content

Keep typed text when pasting a rich-message fragment - #254

Open
f4rceful wants to merge 4 commits into
TelegramMessenger:masterfrom
f4rceful:fix/keep-typed-text-when-pasting-rich-fragment
Open

f4rceful wants to merge 4 commits into
TelegramMessenger:masterfrom
f4rceful:fix/keep-typed-text-when-pasting-rich-fragment

Conversation

@f4rceful

@f4rceful f4rceful commented Nov 5, 2026 •

Copy link
Copy Markdown

Key change

Pasting a selection copied from a rich message opens the rich text editor seeded with that fragment. The text already typed in the message input is now moved into the editor as well, around the pasted fragment at the caret (text before the caret + fragment + text after; a selection is replaced like a normal paste), and the input is cleared — the same way the attach-menu entry consumes the composer text.

Reason

Fixes https://bugs.telegram.org/c/66903.

The paste path (showRichTextEditor(chatInteraction:seeding:)) opened the editor with only the fragment. On close, onCancel(.plain) replaced the input state with the editor's text, so anything typed before the paste was lost. The attach-menu path (showRichTextEditor(chatInteraction:morphSource:)) didn't have the problem because it moves the composer text into the editor first. When the composer holds a structural rich draft, behavior is unchanged.

Video result (before/after)

Before

https://youtu.be/MCSZHGuGn3Q

After

https://youtu.be/wm6tyhSA_zk

Confirmation

  1. Typed text in the message input without sending.
  2. Selected and copied (⌘C) part of a rich message, then pasted (⌘V) into the input.
  3. Expected and actual: the rich text editor opens with the typed text plus the pasted fragment; closing it (Esc) leaves both in the input.
  4. Also checked pasting with the caret in the middle of the typed text — the fragment lands at the caret.

Tested on macOS 27.2, Debug build from master @ 5611693, Xcode 27.1 beta (built with the local scripts/xcode27.sh changes, not committed).

  • I confirm that I have tested the affected behavior and verified that it works properly, or verified the content and links for a documentation-only change.

Pasting a selection copied from a rich message opens the rich text
editor seeded with the fragment, but the text already typed in the
message input was not moved into the editor, and closing the editor
replaced the input with the editor's content, losing it.

Move the composer text into the seeded editor around the pasted
fragment at the caret, the same way the attach-menu entry consumes it.

Fixes https://bugs.telegram.org/c/66903
@f4rceful
f4rceful marked this pull request as ready for review November 5, 2026 15:20
@macosswift

Copy link
Copy Markdown
Collaborator

This branch has conflicts that must be resolved

Please update this branch against master and resolve the merge conflicts so we can continue the review.

@macosswift

Copy link
Copy Markdown
Collaborator

Issues

  • Pasting rich content with an attachment while editing an existing message clears the edit field and starts a new-message preview. Sending from that preview sends a new message. Please preserve the edit session and keep the pasted content in the existing edit flow.

@f4rceful
f4rceful force-pushed the fix/keep-typed-text-when-pasting-rich-fragment branch from 1063f28 to 087b939 Compare November 15, 2026 10:54
@macosswift

Copy link
Copy Markdown
Collaborator

Issues

  • Please preserve whitespace and blank lines around a rich paste. subInputState(from:) trims each side, so inserting at the caret in hello | world still loses both spaces. The refetched-media path also preserves surrounding draft text only while editing. Please cover both clipboard representations in the normal composer and in Edit.

@macosswift

Copy link
Copy Markdown
Collaborator

Issues:

  • Please preserve whitespace and blank lines around rich paste. The refetched-media path also needs to preserve the surrounding draft in the normal composer.

The changed files pass the contributor file allowlist. Earlier review details

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