diff --git a/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift b/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift index 22e51eaca6..8b3028fd82 100644 --- a/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift +++ b/submodules/AttachmentTextInputPanelNode/Sources/AttachmentTextInputPanelNode.swift @@ -1451,54 +1451,58 @@ public class AttachmentTextInputPanelNode: ASDisplayNode, TGCaptionPanelView, AS public func editableTextNodeMenu(_ editableTextNode: ASEditableTextNode, forTextRange textRange: NSRange, suggestedActions: [UIMenuElement]) -> UIMenu { var actions = suggestedActions - var children: [UIAction] = [ - UIAction(title: self.strings?.TextFormat_Bold ?? "Bold", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesBold(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Italic ?? "Italic", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesItalic(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Monospace ?? "Monospace", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesMonospace(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Link ?? "Link", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesLink(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Strikethrough ?? "Strikethrough", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesStrikethrough(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Underline ?? "Underline", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesUnderline(strongSelf) + if editableTextNode.attributedText == nil || editableTextNode.attributedText!.length == 0 || editableTextNode.selectedRange.length == 0 { + + } else { + var children: [UIAction] = [ + UIAction(title: self.strings?.TextFormat_Bold ?? "Bold", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesBold(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Italic ?? "Italic", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesItalic(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Monospace ?? "Monospace", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesMonospace(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Link ?? "Link", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesLink(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Strikethrough ?? "Strikethrough", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesStrikethrough(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Underline ?? "Underline", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesUnderline(strongSelf) + } } + ] + + var hasSpoilers = true + if self.presentationInterfaceState?.chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat { + hasSpoilers = false } - ] - - var hasSpoilers = true - if self.presentationInterfaceState?.chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat { - hasSpoilers = false + + if hasSpoilers { + children.append(UIAction(title: self.strings?.TextFormat_Spoiler ?? "Spoiler", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesSpoiler(strongSelf) + } + }) + } + + let formatMenu = UIMenu(title: self.strings?.TextFormat_Format ?? "Format", image: nil, children: children) + actions.insert(formatMenu, at: 3) } - - if hasSpoilers { - children.append(UIAction(title: self.strings?.TextFormat_Spoiler ?? "Spoiler", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesSpoiler(strongSelf) - } - }) - } - - let formatMenu = UIMenu(title: self.strings?.TextFormat_Format ?? "Format", image: nil, children: children) - actions.insert(formatMenu, at: 3) return UIMenu(children: actions) } diff --git a/submodules/ComposePollUI/Sources/CreatePollTextInputItem.swift b/submodules/ComposePollUI/Sources/CreatePollTextInputItem.swift index 0f6dc11345..b08ccbddb6 100644 --- a/submodules/ComposePollUI/Sources/CreatePollTextInputItem.swift +++ b/submodules/ComposePollUI/Sources/CreatePollTextInputItem.swift @@ -459,7 +459,9 @@ public class CreatePollTextInputItemNode: ListViewItemNode, ASEditableTextNodeDe public func editableTextNodeMenu(_ editableTextNode: ASEditableTextNode, forTextRange textRange: NSRange, suggestedActions: [UIMenuElement]) -> UIMenu { var actions = suggestedActions - if let strings = self.item?.presentationData.strings { + if editableTextNode.attributedText == nil || editableTextNode.attributedText!.length == 0 || editableTextNode.selectedRange.length == 0 { + + } else if let strings = self.item?.presentationData.strings { let children: [UIAction] = [ UIAction(title: strings.TextFormat_Bold, image: nil) { [weak self] (action) in if let strongSelf = self { diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index 7d88bcb22c..90f226dbb3 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -3052,54 +3052,58 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { func editableTextNodeMenu(_ editableTextNode: ASEditableTextNode, forTextRange textRange: NSRange, suggestedActions: [UIMenuElement]) -> UIMenu { var actions = suggestedActions - var children: [UIAction] = [ - UIAction(title: self.strings?.TextFormat_Bold ?? "Bold", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesBold(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Italic ?? "Italic", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesItalic(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Monospace ?? "Monospace", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesMonospace(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Link ?? "Link", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesLink(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Strikethrough ?? "Strikethrough", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesStrikethrough(strongSelf) - } - }, - UIAction(title: self.strings?.TextFormat_Underline ?? "Underline", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesUnderline(strongSelf) + if editableTextNode.attributedText == nil || editableTextNode.attributedText!.length == 0 || editableTextNode.selectedRange.length == 0 { + + } else { + var children: [UIAction] = [ + UIAction(title: self.strings?.TextFormat_Bold ?? "Bold", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesBold(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Italic ?? "Italic", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesItalic(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Monospace ?? "Monospace", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesMonospace(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Link ?? "Link", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesLink(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Strikethrough ?? "Strikethrough", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesStrikethrough(strongSelf) + } + }, + UIAction(title: self.strings?.TextFormat_Underline ?? "Underline", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesUnderline(strongSelf) + } } + ] + + var hasSpoilers = true + if self.presentationInterfaceState?.chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat { + hasSpoilers = false } - ] - - var hasSpoilers = true - if self.presentationInterfaceState?.chatLocation.peerId?.namespace == Namespaces.Peer.SecretChat { - hasSpoilers = false + + if hasSpoilers { + children.append(UIAction(title: self.strings?.TextFormat_Spoiler ?? "Spoiler", image: nil) { [weak self] (action) in + if let strongSelf = self { + strongSelf.formatAttributesSpoiler(strongSelf) + } + }) + } + + let formatMenu = UIMenu(title: self.strings?.TextFormat_Format ?? "Format", image: nil, children: children) + actions.insert(formatMenu, at: 3) } - - if hasSpoilers { - children.append(UIAction(title: self.strings?.TextFormat_Spoiler ?? "Spoiler", image: nil) { [weak self] (action) in - if let strongSelf = self { - strongSelf.formatAttributesSpoiler(strongSelf) - } - }) - } - - let formatMenu = UIMenu(title: self.strings?.TextFormat_Format ?? "Format", image: nil, children: children) - actions.insert(formatMenu, at: 3) return UIMenu(children: actions) }