mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix text format menu on iOS 13.2
This commit is contained in:
parent
da67ea139c
commit
636e66b048
@ -71,6 +71,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
//! @abstract The range of text currently selected. If length is zero, the range is the cursor location.
|
||||
@property NSRange selectedRange;
|
||||
|
||||
@property (readonly) CGRect selectionRect;
|
||||
|
||||
#pragma mark - Placeholder
|
||||
/**
|
||||
@abstract Indicates if the receiver is displaying the placeholder text.
|
||||
|
@ -566,6 +566,15 @@
|
||||
_textKitComponents.textView.selectedRange = selectedRange;
|
||||
}
|
||||
|
||||
- (CGRect)selectionRect {
|
||||
UITextRange *range = [_textKitComponents.textView selectedTextRange];
|
||||
if (range != nil) {
|
||||
return [_textKitComponents.textView firstRectForRange:range];
|
||||
} else {
|
||||
return [_textKitComponents.textView bounds];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Placeholder
|
||||
- (BOOL)isDisplayingPlaceholder
|
||||
{
|
||||
|
@ -33,8 +33,6 @@ final class ChatTextInputMenu {
|
||||
UIMenuItem(title: self.stringStrikethrough, action: Selector(("formatAttributesStrikethrough:"))),
|
||||
UIMenuItem(title: self.stringUnderline, action: Selector(("formatAttributesUnderline:")))
|
||||
]
|
||||
UIMenuController.shared.isMenuVisible = true
|
||||
UIMenuController.shared.update()
|
||||
}
|
||||
|
||||
}
|
||||
@ -74,9 +72,15 @@ final class ChatTextInputMenu {
|
||||
self.state = .inactive
|
||||
}
|
||||
|
||||
func format() {
|
||||
func format(view: UIView, rect: CGRect) {
|
||||
if self.state == .general {
|
||||
self.state = .format
|
||||
if #available(iOS 13.0, *) {
|
||||
UIMenuController.shared.showMenu(from: view, rect: rect)
|
||||
} else {
|
||||
UIMenuController.shared.isMenuVisible = true
|
||||
UIMenuController.shared.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1437,6 +1437,12 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
}
|
||||
|
||||
if let textInputNode = self.textInputNode, let presentationInterfaceState = self.presentationInterfaceState {
|
||||
|
||||
if case .format = self.inputMenu.state {
|
||||
self.inputMenu.deactivate()
|
||||
UIMenuController.shared.update()
|
||||
}
|
||||
|
||||
let baseFontSize = max(17.0, presentationInterfaceState.fontSize.baseDisplaySize)
|
||||
refreshChatTextInputTypingAttributes(textInputNode, theme: presentationInterfaceState.theme, baseFontSize: baseFontSize)
|
||||
}
|
||||
@ -1478,7 +1484,9 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
|
||||
}
|
||||
|
||||
@objc func _showTextStyleOptions(_ sender: Any) {
|
||||
self.inputMenu.format()
|
||||
if let textInputNode = self.textInputNode {
|
||||
self.inputMenu.format(view: textInputNode.view, rect: textInputNode.selectionRect.insetBy(dx: 0.0, dy: -1.0))
|
||||
}
|
||||
}
|
||||
|
||||
@objc func formatAttributesBold(_ sender: Any) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user