From bc52f5951fac1808a2f4e1c5b1fa33c759d876a3 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 11 Jan 2022 15:59:47 +0300 Subject: [PATCH] Preserve spoiler formatting when copying to pasterboard --- submodules/TelegramUI/Sources/Pasteboard.swift | 3 +++ .../TextFormat/Sources/StringWithAppliedEntities.swift | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramUI/Sources/Pasteboard.swift b/submodules/TelegramUI/Sources/Pasteboard.swift index 8189c08a48..ee9c88ccc9 100644 --- a/submodules/TelegramUI/Sources/Pasteboard.swift +++ b/submodules/TelegramUI/Sources/Pasteboard.swift @@ -49,6 +49,9 @@ private func chatInputStateString(attributedString: NSAttributedString) -> NSAtt string.addAttribute(ChatTextInputAttributes.monospace, value: true as NSNumber, range: range) } } + if let value = attributes[.backgroundColor] as? UIColor, value.rgb == UIColor.gray.rgb { + string.addAttribute(ChatTextInputAttributes.spoiler, value: true as NSNumber, range: range) + } if let _ = attributes[.strikethroughStyle] { string.addAttribute(ChatTextInputAttributes.strikethrough, value: true as NSNumber, range: range) } diff --git a/submodules/TextFormat/Sources/StringWithAppliedEntities.swift b/submodules/TextFormat/Sources/StringWithAppliedEntities.swift index 98cd2dc58d..b1a9870d83 100644 --- a/submodules/TextFormat/Sources/StringWithAppliedEntities.swift +++ b/submodules/TextFormat/Sources/StringWithAppliedEntities.swift @@ -228,7 +228,11 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti } string.addAttribute(NSAttributedString.Key(rawValue: TelegramTextAttributes.BankCard), value: nsString!.substring(with: range), range: range) case .Spoiler: - string.addAttribute(NSAttributedString.Key(rawValue: TelegramTextAttributes.Spoiler), value: true as NSNumber, range: range) + if external { + string.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.gray, range: range) + } else { + string.addAttribute(NSAttributedString.Key(rawValue: TelegramTextAttributes.Spoiler), value: true as NSNumber, range: range) + } case let .Custom(type): if type == ApplicationSpecificEntityType.Timecode { string.addAttribute(NSAttributedString.Key.foregroundColor, value: linkColor, range: range)