Skip to content

Commit

Permalink
Fix an issue that causes the pinned tab previews to stay on screen wh…
Browse files Browse the repository at this point in the history
…en hovering on the semaphore buttons and exiting fullscreen
  • Loading branch information
alessandroboron committed May 16, 2024
1 parent 767ae9d commit 630bb49
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion DuckDuckGo/TabBar/View/TabBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,32 @@ final class TabBarViewController: NSViewController {
}

private func pinnedTabsViewDidUpdateHoveredItem(to index: Int?) {
func shouldDismissPinnedTabPreview() -> Bool {
// If the point is not within the view we can safely dismiss the preview
guard let pointWithinView = self.view.mouseLocationInsideBounds(nil) else {
return true
}

// Calculate the rect of the standard tabs
let standardTabsTotalWidth = self.collectionView.visibleItems().reduce(into: 0.0) { partial, item in
partial += item.view.bounds.width
}

// Create a rect with the width of pinned and non pinned tabs
var standardAndPinnedTabsContainerRect = self.pinnedTabsContainerView.frame
standardAndPinnedTabsContainerRect.size.width += standardTabsTotalWidth

// If the point is not within the rect dismiss the preview
return !standardAndPinnedTabsContainerRect.contains(pointWithinView)
}

if let index = index {
showPinnedTabPreview(at: index)
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
if self.view.isMouseLocationInsideBounds() == false {
// When the mouse hover on top of the semaphore view we want to dismiss the preview to avoid the preview get stuck on screen when the popover to choose the screen size is shown.
// We don't want to dismiss the preview if the location of the mouse is within the rect that encompasses the pinned and standard tabs
if shouldDismissPinnedTabPreview() {
self.hideTabPreview(allowQuickRedisplay: true)
}
}
Expand Down

0 comments on commit 630bb49

Please sign in to comment.