Skip to content

Commit

Permalink
Search bar clickable area is too small (#2787)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alessandroboron authored May 16, 2024
1 parent 07ede78 commit 701cdbc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DuckDuckGo/NavigationBar/View/AddressBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down Expand Up @@ -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? {
Expand Down

0 comments on commit 701cdbc

Please sign in to comment.