diff --git a/submodules/Pasteboard/Sources/Pasteboard.swift b/submodules/Pasteboard/Sources/Pasteboard.swift index bbd784a466..7ffa9fc9d4 100644 --- a/submodules/Pasteboard/Sources/Pasteboard.swift +++ b/submodules/Pasteboard/Sources/Pasteboard.swift @@ -53,15 +53,29 @@ private func chatInputStateString(attributedString: NSAttributedString) -> NSAtt } if let value = attributes[.font], let font = value as? UIFont { let fontName = font.fontName.lowercased() - if fontName.contains("bolditalic") { - string.addAttribute(ChatTextInputAttributes.bold, value: true as NSNumber, range: range) - string.addAttribute(ChatTextInputAttributes.italic, value: true as NSNumber, range: range) - } else if fontName.contains("bold") { - string.addAttribute(ChatTextInputAttributes.bold, value: true as NSNumber, range: range) - } else if fontName.contains("italic") { - string.addAttribute(ChatTextInputAttributes.italic, value: true as NSNumber, range: range) - } else if fontName.contains("menlo") || fontName.contains("courier") || fontName.contains("sfmono") { - string.addAttribute(ChatTextInputAttributes.monospace, value: true as NSNumber, range: range) + if fontName.hasPrefix(".sfui") { + let traits = font.fontDescriptor.symbolicTraits + if traits.contains(.traitMonoSpace) { + string.addAttribute(ChatTextInputAttributes.monospace, value: true as NSNumber, range: range) + } else { + if traits.contains(.traitBold) { + string.addAttribute(ChatTextInputAttributes.bold, value: true as NSNumber, range: range) + } + if traits.contains(.traitItalic) { + string.addAttribute(ChatTextInputAttributes.italic, value: true as NSNumber, range: range) + } + } + } else { + if fontName.contains("bolditalic") { + string.addAttribute(ChatTextInputAttributes.bold, value: true as NSNumber, range: range) + string.addAttribute(ChatTextInputAttributes.italic, value: true as NSNumber, range: range) + } else if fontName.contains("bold") { + string.addAttribute(ChatTextInputAttributes.bold, value: true as NSNumber, range: range) + } else if fontName.contains("italic") { + string.addAttribute(ChatTextInputAttributes.italic, value: true as NSNumber, range: range) + } else if fontName.contains("menlo") || fontName.contains("courier") || fontName.contains("sfmono") { + string.addAttribute(ChatTextInputAttributes.monospace, value: true as NSNumber, range: range) + } } } if let value = attributes[.backgroundColor] as? UIColor, value.rgb == UIColor.gray.rgb { diff --git a/submodules/TelegramUI/BUILD b/submodules/TelegramUI/BUILD index 3f0e1ae3d6..4c64d17ab7 100644 --- a/submodules/TelegramUI/BUILD +++ b/submodules/TelegramUI/BUILD @@ -70,6 +70,7 @@ swift_library( "//submodules/MediaPlayer:UniversalMediaPlayer", "//submodules/TelegramVoip:TelegramVoip", "//submodules/DeviceAccess:DeviceAccess", + "//submodules/Utils/DeviceModel", "//submodules/WatchCommon/Host:WatchCommon", "//submodules/BuildConfig:BuildConfig", "//submodules/BuildConfigExtra:BuildConfigExtra", diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index 193ccfa97b..1e884bf566 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -1,4 +1,5 @@ import Foundation +import UniformTypeIdentifiers import UIKit import Display import AsyncDisplayKit @@ -44,6 +45,7 @@ import TelegramNotices import AnimatedCountLabelNode import TelegramStringFormatting import TextNodeWithEntities +import DeviceModel private let accessoryButtonFont = Font.medium(14.0) private let counterFont = Font.with(size: 14.0, design: .regular, traits: [.monospacedNumbers]) @@ -4473,10 +4475,14 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate, Ch var attributedString: NSAttributedString? if let data = pasteboard.data(forPasteboardType: "private.telegramtext"), let value = chatInputStateStringFromAppSpecificString(data: data) { attributedString = value - } else if let data = pasteboard.data(forPasteboardType: kUTTypeRTF as String) { + } else if let data = pasteboard.data(forPasteboardType: "public.rtf") { attributedString = chatInputStateStringFromRTF(data, type: NSAttributedString.DocumentType.rtf) } else if let data = pasteboard.data(forPasteboardType: "com.apple.flat-rtfd") { - attributedString = chatInputStateStringFromRTF(data, type: NSAttributedString.DocumentType.rtfd) + if let _ = pasteboard.data(forPasteboardType: "com.apple.notes.richtext"), DeviceModel.current.isIpad, let htmlData = pasteboard.data(forPasteboardType: "public.html") { + attributedString = chatInputStateStringFromRTF(htmlData, type: NSAttributedString.DocumentType.html) + } else { + attributedString = chatInputStateStringFromRTF(data, type: NSAttributedString.DocumentType.rtfd) + } } if let attributedString = attributedString {