From b19140c0b4cc7ffc6ccceb033a66f55474d04ed9 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 7 Apr 2026 15:56:28 +0000 Subject: [PATCH] fix: enable link click handling in VSelectableTextView Add NSTextViewDelegate to Coordinator with textView(_:clickedOnLink:at:) to open clicked links in the default browser via NSWorkspace. The NSTextView was already styling links (tint color, underline, pointer cursor) but had no delegate to handle click events, making links visually styled but inert. Closes LUM-748 Co-Authored-By: ashlee@vellum.ai --- .../Display/SelectableTextView.swift | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/clients/shared/DesignSystem/Components/Display/SelectableTextView.swift b/clients/shared/DesignSystem/Components/Display/SelectableTextView.swift index 7e4930db9cb..2a9a90bcbc6 100644 --- a/clients/shared/DesignSystem/Components/Display/SelectableTextView.swift +++ b/clients/shared/DesignSystem/Components/Display/SelectableTextView.swift @@ -143,6 +143,8 @@ public struct VSelectableTextView: NSViewRepresentable { textView.autoresizingMask = [.width] textView.textContainerInset = .zero + textView.delegate = context.coordinator + textView.linkTextAttributes = [ .foregroundColor: tintColor, .underlineStyle: NSUnderlineStyle.single.rawValue, @@ -193,7 +195,7 @@ public struct VSelectableTextView: NSViewRepresentable { public func makeCoordinator() -> Coordinator { Coordinator() } - public final class Coordinator { + public final class Coordinator: NSObject, NSTextViewDelegate { var lastAttributedString: NSAttributedString? var lastLineSpacing: CGFloat = 0 private var pendingAttributedString: NSAttributedString? @@ -240,6 +242,22 @@ public struct VSelectableTextView: NSViewRepresentable { } } + // MARK: - NSTextViewDelegate + + /// Opens clicked links in the default browser. + /// Reference: https://developer.apple.com/documentation/appkit/nstextviewdelegate/textview(_:clickedonlink:at:) + public func textView(_ textView: NSTextView, clickedOnLink link: Any, at charIndex: Int) -> Bool { + if let url = link as? URL { + NSWorkspace.shared.open(url) + return true + } + if let string = link as? String, let url = URL(string: string) { + NSWorkspace.shared.open(url) + return true + } + return false + } + func applyAttributedString( _ attributedString: NSAttributedString, lineSpacing: CGFloat,