From 701cdbcf2091eb4a3008ea9e6c79ba19d86986f9 Mon Sep 17 00:00:00 2001 From: Alessandro Boron Date: Fri, 17 May 2024 09:18:55 +1000 Subject: [PATCH] Search bar clickable area is too small (#2787) Task/Issue URL: https://app.asana.com/0/1177771139624306/1203899219213416/f **Description**: This PR fixes the clickable area of the AddressBar by intercepting right-clicks in the `AddressBarViewController` and forwarding them to the `AddressBarTextField` if necessary. --- .../View/AddressBarViewController.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift b/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift index 51c3ca308a..42c1ce7869 100644 --- a/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift +++ b/DuckDuckGo/NavigationBar/View/AddressBarViewController.swift @@ -461,6 +461,10 @@ extension AddressBarViewController { guard let self else { return event } return self.mouseUp(with: event) }.store(in: &eventMonitorCancellables) + NSEvent.addLocalCancellableMonitor(forEventsMatching: .rightMouseDown) { [weak self] event in + guard let self else { return event } + return self.rightMouseDown(with: event) + }.store(in: &eventMonitorCancellables) } func mouseDown(with event: NSEvent) -> NSEvent? { @@ -491,6 +495,22 @@ extension AddressBarViewController { return event } + func rightMouseDown(with event: NSEvent) -> NSEvent? { + guard event.window === self.view.window else { return event } + // Convert the point to view system + let pointInView = view.convert(event.locationInWindow, from: nil) + + // If the view where the touch occurred is outside the AddressBar forward the event + guard let viewWithinAddressBar = view.hitTest(pointInView) else { return event } + + // If the farthest view of the point location is a NSButton or LottieAnimationView don't show contextual menu + guard viewWithinAddressBar.shouldShowArrowCursor == false else { return nil } + + // The event location is not a button so we can forward the event to the textfield + addressBarTextField.rightMouseDown(with: event) + return nil + } + private static let maxClickReleaseDistanceToResignFirstResponder: CGFloat = 4 func mouseUp(with event: NSEvent) -> NSEvent? {