Skip to content

Commit

Permalink
show X on Tab when Cmd is pressed (#3241)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1202406491309510/1206714287520246/f

**Description**:
- Display X button on Tab in compact mode when Cmd is pressed

**Steps to test this PR**:
1. Open many tabs to enter the overflown mode
2. Press Cmd, validate X button appears on a hovered tab when Cmd is
pressed

<!--
Tagging instructions
If this PR isn't ready to be merged for whatever reason it should be
marked with the `DO NOT MERGE` label (particularly if it's a draft)
If it's pending Product Review/PFR, please add the `Pending Product
Review` label.

If at any point it isn't actively being worked on/ready for
review/otherwise moving forward (besides the above PR/PFR exception)
strongly consider closing it (or not opening it in the first place). If
you decide not to close it, make sure it's labelled to make it clear the
PRs state and comment with more information.
-->

**Definition of Done**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
mallexxx authored Oct 18, 2024
1 parent 5892e49 commit 6de0fcc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion DuckDuckGo/TabBar/View/TabBarViewItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ final class TabBarItemCellView: NSView {
if permissionButton.isShown {
// make permission button from 16 to 24pt wide depending of available space
permissionButton.frame = NSRect(x: x.rounded() - spacing.rounded(), y: bounds.midY - 12, width: 16 + spacing.rounded() * 2, height: 24)
x = permissionButton.frame.maxX
}
if closeButton.isShown {
// close button appears in place of favicon in compact mode
closeButton.frame = NSRect(x: x.rounded(), y: bounds.midY - 8, width: 16, height: 16)
x = closeButton.frame.maxX + spacing
}
}

Expand Down Expand Up @@ -609,7 +615,7 @@ final class TabBarViewItem: NSCollectionViewItem {
cell.borderLayer.isHidden = !isSelected
}

let showCloseButton = (isMouseOver && !widthStage.isCloseButtonHidden) || isSelected
let showCloseButton = (isMouseOver && (!widthStage.isCloseButtonHidden || NSApp.isCommandPressed)) || isSelected
cell.closeButton.isShown = showCloseButton
cell.faviconImageView.isShown = (cell.faviconImageView.image != nil) && (widthStage != .withoutTitle || !showCloseButton)
updateSeparatorView()
Expand Down Expand Up @@ -837,6 +843,15 @@ extension TabBarViewItem: MouseClickViewDelegate {
delegate?.tabBarViewItem(self, isMouseOver: isMouseOver)
self.isMouseOver = isMouseOver
view.needsLayout = true
eventMonitor = isMouseOver ? NSEvent.addLocalMonitorForEvents(matching: .flagsChanged) { [weak self] event in
if let self, widthStage.isCloseButtonHidden {
view.needsLayout = true
}
return event
} : nil

delegate?.tabBarViewItem(self, isMouseOver: isMouseOver)
self.isMouseOver = isMouseOver
}

func mouseClickView(_ mouseClickView: MouseClickView, otherMouseDownEvent: NSEvent) {
Expand Down

0 comments on commit 6de0fcc

Please sign in to comment.