From 4493a1e72408df7a8de0a3e7eb2b1d3c8ec03ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Fri, 28 Aug 2026 13:43:09 +0200 Subject: [PATCH] fix: Opening links in messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Marcel Müller --- .../Chat/Chat views/MessageBodyTextView.swift | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/NextcloudTalk/Chat/Chat views/MessageBodyTextView.swift b/NextcloudTalk/Chat/Chat views/MessageBodyTextView.swift index 563941b48..80bafc4ef 100644 --- a/NextcloudTalk/Chat/Chat views/MessageBodyTextView.swift +++ b/NextcloudTalk/Chat/Chat views/MessageBodyTextView.swift @@ -37,7 +37,9 @@ struct MessageBodyTextViewWrapper: UIViewRepresentable { } } -class MessageBodyTextView: UITextView, UITextViewDelegate { +class MessageBodyTextView: UITextView, UITextViewDelegate, UIGestureRecognizerDelegate { + + private var codeBlockGestureRecognizer: UITapGestureRecognizer? init() { let textStorage = NSTextStorage() @@ -70,9 +72,12 @@ class MessageBodyTextView: UITextView, UITextViewDelegate { self.delegate = self let codeBlockGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleCodeBlockTap(_:))) + self.codeBlockGestureRecognizer = codeBlockGestureRecognizer // Don't swallow the touch, links and the message context menu need to see it as well codeBlockGestureRecognizer.cancelsTouchesInView = false + codeBlockGestureRecognizer.delegate = self + self.addGestureRecognizer(codeBlockGestureRecognizer) } @@ -164,6 +169,13 @@ class MessageBodyTextView: UITextView, UITextViewDelegate { NCUserInterfaceController.sharedInstance().mainViewController.present(navigationController, animated: true) } + // MARK: - UIGestureRecognizer delegate + + func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { + // Without this our tap cancels the text view's own recognizer, which opens links + return gestureRecognizer === self.codeBlockGestureRecognizer + } + // MARK: - UITextView delegate func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {