diff --git a/submodules/GalleryUI/Sources/RecognizedTextSelectionNode.swift b/submodules/GalleryUI/Sources/RecognizedTextSelectionNode.swift index 667c268f42..64fcc28b6d 100644 --- a/submodules/GalleryUI/Sources/RecognizedTextSelectionNode.swift +++ b/submodules/GalleryUI/Sources/RecognizedTextSelectionNode.swift @@ -82,7 +82,7 @@ private enum Knob { case right } -private final class RecognizedTextSelectionGetureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { +private final class RecognizedTextSelectionGestureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { private var longTapTimer: Timer? private var movingKnob: (Knob, CGPoint, CGPoint)? private var currentLocation: CGPoint? @@ -225,7 +225,7 @@ public final class RecognizedTextSelectionNode: ASDisplayNode { public let highlightAreaNode: ASDisplayNode - private var recognizer: RecognizedTextSelectionGetureRecognizer? + private var recognizer: RecognizedTextSelectionGestureRecognizer? public init(size: CGSize, theme: RecognizedTextSelectionTheme, strings: PresentationStrings, recognitions: [RecognizedContent], updateIsActive: @escaping (Bool) -> Void, present: @escaping (ViewController, Any?) -> Void, rootNode: ASDisplayNode, performAction: @escaping (String, RecognizedTextSelectionAction) -> Void) { self.size = size @@ -286,7 +286,7 @@ public final class RecognizedTextSelectionNode: ASDisplayNode { return self?.hitTest(point, with: event) } - let recognizer = RecognizedTextSelectionGetureRecognizer(target: nil, action: nil) + let recognizer = RecognizedTextSelectionGestureRecognizer(target: nil, action: nil) recognizer.knobAtPoint = { [weak self] point in return self?.knobAtPoint(point) } diff --git a/submodules/InstantPageUI/Sources/InstantPageTextSelectionNode.swift b/submodules/InstantPageUI/Sources/InstantPageTextSelectionNode.swift index 7998e30d92..8595882e5b 100644 --- a/submodules/InstantPageUI/Sources/InstantPageTextSelectionNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageTextSelectionNode.swift @@ -67,7 +67,7 @@ private enum Knob { case right } -private final class InstantPageTextSelectionGetureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { +private final class InstantPageTextSelectionGestureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { private var longTapTimer: Timer? private var movingKnob: (Knob, CGPoint, CGPoint)? private var currentLocation: CGPoint? @@ -220,7 +220,7 @@ final class InstantPageTextSelectionNode: ASDisplayNode { public let highlightAreaNode: ASDisplayNode - private var recognizer: InstantPageTextSelectionGetureRecognizer? + private var recognizer: InstantPageTextSelectionGestureRecognizer? private var displayLinkAnimator: DisplayLinkAnimator? public init(theme: InstantPageTextSelectionTheme, strings: PresentationStrings, textItemAtLocation: @escaping (CGPoint) -> (InstantPageTextItem, CGPoint)?, updateIsActive: @escaping (Bool) -> Void, present: @escaping (ViewController, Any?) -> Void, rootNode: ASDisplayNode, performAction: @escaping (String, InstantPageTextSelectionAction) -> Void) { @@ -263,7 +263,7 @@ final class InstantPageTextSelectionNode: ASDisplayNode { return self?.hitTest(point, with: event) } - let recognizer = InstantPageTextSelectionGetureRecognizer(target: nil, action: nil) + let recognizer = InstantPageTextSelectionGestureRecognizer(target: nil, action: nil) recognizer.knobAtPoint = { [weak self] point in return self?.knobAtPoint(point) } diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 1a79f24f16..f5cdbeb5fd 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -9666,6 +9666,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var presentationInterfaceState = ChatPresentationInterfaceState(chatWallpaper: .builtin(WallpaperSettings()), theme: presentationData.theme, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, limitsConfiguration: self.context.currentLimitsConfiguration.with { $0 }, fontSize: presentationData.chatFontSize, bubbleCorners: presentationData.chatBubbleCorners, accountPeerId: self.context.account.peerId, mode: .standard(previewing: false), chatLocation: .peer(PeerId(0)), subject: nil, peerNearbyData: nil, greetingData: nil, pendingUnpinnedAllMessages: false, activeGroupCallInfo: nil, hasActiveGroupCall: false, importState: nil) var updateChatPresentationInterfaceStateImpl: (((ChatPresentationInterfaceState) -> ChatPresentationInterfaceState) -> Void)? + var ensureFocusedImpl: (() -> Void)? let interfaceInteraction = ChatPanelInterfaceInteraction(updateTextInputStateAndMode: { f in updateChatPresentationInterfaceStateImpl?({ @@ -9708,6 +9709,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }) }) } + ensureFocusedImpl?() updateChatPresentationInterfaceStateImpl?({ return $0.updatedInputMode({ _ in return inputMode }).updatedInterfaceState({ $0.withUpdatedEffectiveInputState(ChatTextInputState(inputText: $0.effectiveInputState.inputText, selectionRange: selectionRange.endIndex ..< selectionRange.endIndex)) @@ -9736,6 +9738,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } + ensureFocusedImpl = { [weak inputPanelNode] in + inputPanelNode?.ensureFocused() + } + return inputPanelNode } diff --git a/submodules/TelegramUI/Sources/PeerSelectionControllerNode.swift b/submodules/TelegramUI/Sources/PeerSelectionControllerNode.swift index b513365219..c8b51ace9f 100644 --- a/submodules/TelegramUI/Sources/PeerSelectionControllerNode.swift +++ b/submodules/TelegramUI/Sources/PeerSelectionControllerNode.swift @@ -286,8 +286,8 @@ final class PeerSelectionControllerNode: ASDisplayNode { return state }) - let controller = chatTextLinkEditController(sharedContext: strongSelf.context.sharedContext, updatedPresentationData: (presentationData, .never()), account: strongSelf.context.account, text: text ?? "", link: nil, apply: { link in - if let inputMode = inputMode, let selectionRange = selectionRange { + let controller = chatTextLinkEditController(sharedContext: strongSelf.context.sharedContext, updatedPresentationData: (presentationData, .never()), account: strongSelf.context.account, text: text ?? "", link: nil, apply: { [weak self] link in + if let strongSelf = self, let inputMode = inputMode, let selectionRange = selectionRange { if let link = link { strongSelf.updateChatPresentationInterfaceState(animated: true, { state in return state.updatedInterfaceState({ @@ -295,6 +295,9 @@ final class PeerSelectionControllerNode: ASDisplayNode { }) }) } + if let textInputPanelNode = strongSelf.textInputPanelNode { + textInputPanelNode.ensureFocused() + } strongSelf.updateChatPresentationInterfaceState(animated: true, { state in return state.updatedInputMode({ _ in return inputMode }).updatedInterfaceState({ $0.withUpdatedEffectiveInputState(ChatTextInputState(inputText: $0.effectiveInputState.inputText, selectionRange: selectionRange.endIndex ..< selectionRange.endIndex)) diff --git a/submodules/TelegramUI/Sources/PeerSelectionTextInputPanelNode.swift b/submodules/TelegramUI/Sources/PeerSelectionTextInputPanelNode.swift index e078994d54..6475fb6c97 100644 --- a/submodules/TelegramUI/Sources/PeerSelectionTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/PeerSelectionTextInputPanelNode.swift @@ -322,7 +322,7 @@ class PeerSelectionTextInputPanelNode: ChatInputPanelNode, TGCaptionPanelView, A } public func dismissInput() { - self.view.window?.endEditing(true) + self.ensureUnfocused() } public func baseHeight() -> CGFloat { @@ -614,7 +614,7 @@ class PeerSelectionTextInputPanelNode: ChatInputPanelNode, TGCaptionPanelView, A } if self.isCaption { - if !(self.textInputNode?.isFirstResponder() ?? false) { + if !self.isFocused { panelHeight = minimalHeight transition.updateAlpha(node: self.oneLineNode, alpha: inputHasText ? 1.0 : 0.0) @@ -942,8 +942,12 @@ class PeerSelectionTextInputPanelNode: ChatInputPanelNode, TGCaptionPanelView, A } } + private var imitateFocus = false @objc func formatAttributesLink(_ sender: Any) { self.inputMenu.back() + if self.isCaption { + self.imitateFocus = true + } self.interfaceInteraction?.openLinkEditing() } @@ -1061,6 +1065,9 @@ class PeerSelectionTextInputPanelNode: ChatInputPanelNode, TGCaptionPanelView, A } var isFocused: Bool { + if self.imitateFocus { + return true + } return self.textInputNode?.isFirstResponder() ?? false } @@ -1069,6 +1076,8 @@ class PeerSelectionTextInputPanelNode: ChatInputPanelNode, TGCaptionPanelView, A } func ensureFocused() { + self.imitateFocus = false + if self.textInputNode == nil { self.loadTextInputNode() } diff --git a/submodules/TextSelectionNode/Sources/TextSelectionNode.swift b/submodules/TextSelectionNode/Sources/TextSelectionNode.swift index f57f7c1c16..93f3111b3d 100644 --- a/submodules/TextSelectionNode/Sources/TextSelectionNode.swift +++ b/submodules/TextSelectionNode/Sources/TextSelectionNode.swift @@ -67,7 +67,7 @@ private enum Knob { case right } -private final class TextSelectionGetureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { +private final class TextSelectionGestureRecognizer: UIGestureRecognizer, UIGestureRecognizerDelegate { private var longTapTimer: Timer? private var movingKnob: (Knob, CGPoint, CGPoint)? private var currentLocation: CGPoint? @@ -207,7 +207,7 @@ public final class TextSelectionNode: ASDisplayNode { public let highlightAreaNode: ASDisplayNode - private var recognizer: TextSelectionGetureRecognizer? + private var recognizer: TextSelectionGestureRecognizer? private var displayLinkAnimator: DisplayLinkAnimator? public init(theme: TextSelectionTheme, strings: PresentationStrings, textNode: TextNode, updateIsActive: @escaping (Bool) -> Void, present: @escaping (ViewController, Any?) -> Void, rootNode: ASDisplayNode, performAction: @escaping (NSAttributedString, TextSelectionAction) -> Void) { @@ -250,7 +250,7 @@ public final class TextSelectionNode: ASDisplayNode { return self?.hitTest(point, with: event) } - let recognizer = TextSelectionGetureRecognizer(target: nil, action: nil) + let recognizer = TextSelectionGestureRecognizer(target: nil, action: nil) recognizer.knobAtPoint = { [weak self] point in return self?.knobAtPoint(point) }