Skip to content

Fix code/monospace formatting lost on copy-paste#1386

Open
ettyxne wants to merge 1 commit into
overtake:masterfrom
ettyxne:fix/monospace-copy-paste
Open

Fix code/monospace formatting lost on copy-paste#1386
ettyxne wants to merge 1 commit into
overtake:masterfrom
ettyxne:fix/monospace-copy-paste

Conversation

@ettyxne
Copy link
Copy Markdown

@ettyxne ettyxne commented May 12, 2026

Copying text that contains inline code or monospace runs and pasting it back into Telegram loses the formatting.

Root cause: Two removeAttribute(.code/.monospace) calls were made on modified before ChatTextInputState was built from it. Since NSMutableAttributedString is a reference type, mutating it afterward affects the already-captured attributedText — so the kInApp pasteboard entry ends up with no code/monospace runs.

Fix: Remove those two removeAttribute calls. refreshTextInputAttributes already applies NSFont.code() as the .font attribute on every code/monospace run, so RTF export naturally produces monospace output with no extra work needed.

Two smaller fixes included:

  • Declare all three pasteboard types (.rtf, .kInApp, .string) upfront before setting any values, as required by the NSPasteboard API contract
  • Always write the plain-string fallback regardless of whether RTF generation succeeded

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 12, 2026

CLA assistant check
All committers have signed the CLA.

Copying formatted text strips the code and monospace attributes from
the kInApp pasteboard entry, so pasting back into Telegram loses the
formatting.

The bug: removeAttribute(.code/.monospace) was called on `modified`
before building ChatTextInputState from it. Since NSMutableAttributedString
is a reference type, mutating it afterward affects the already-captured
attributedText, so the encoded kInApp data has no code/monospace runs.

Fix: remove those two removeAttribute calls. refreshTextInputAttributes
already sets .font to NSFont.code() on every code/monospace run, so RTF
export naturally produces monospace output with no extra work.

Also move .string out of the `if let rtf` branch and declare all three
pasteboard types upfront, as required by the NSPasteboard API contract.
@ettyxne ettyxne force-pushed the fix/monospace-copy-paste branch from 4fbbc1a to 0baac64 Compare May 12, 2026 18:01
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