@@ -15,14 +15,23 @@ class FatSidebarItemOverlay: FatSidebarItem {
15
15
// MARK: - Hovering
16
16
17
17
static var hoverStarted : Notification . Name { return Notification . Name ( rawValue: " fat sidebar hover did start " ) }
18
+ var didExit = false
18
19
var overlayFinished : ( ( ) -> Void ) ?
19
20
20
21
private var trackingArea : NSTrackingArea ?
21
22
22
23
override func updateTrackingAreas( ) {
23
24
super. updateTrackingAreas ( )
24
25
25
- if let oldTrackingArea = trackingArea { self . removeTrackingArea ( oldTrackingArea) }
26
+ if let oldTrackingArea = self . trackingArea { self . removeTrackingArea ( oldTrackingArea) }
27
+
28
+ guard !didExit else { return }
29
+
30
+ createAndAssignTrackingArea ( )
31
+ fireEnteredOrExitedWithInitialMouseCoordinates ( )
32
+ }
33
+
34
+ fileprivate func createAndAssignTrackingArea( ) {
26
35
27
36
let newTrackingArea = NSTrackingArea (
28
37
rect: self . bounds,
@@ -33,7 +42,25 @@ class FatSidebarItemOverlay: FatSidebarItem {
33
42
self . trackingArea = newTrackingArea
34
43
}
35
44
45
+ fileprivate func fireEnteredOrExitedWithInitialMouseCoordinates( ) {
46
+
47
+ guard let absoluteMousePoint = self . window? . mouseLocationOutsideOfEventStream else { return }
48
+
49
+ let mousePoint = self . convert ( absoluteMousePoint, from: nil )
50
+
51
+ if NSPointInRect ( mousePoint, self . bounds) {
52
+ mouseDidEnter ( )
53
+ } else {
54
+ mouseDidExit ( )
55
+ }
56
+ }
57
+
36
58
override func mouseEntered( with event: NSEvent ) {
59
+ mouseDidEnter ( )
60
+ }
61
+
62
+ /// - note: Use when event is not available, as in `updateTrackingRect`.
63
+ fileprivate func mouseDidEnter( ) {
37
64
38
65
self . window? . disableCursorRects ( )
39
66
NSCursor . pointingHand ( ) . set ( )
@@ -50,7 +77,13 @@ class FatSidebarItemOverlay: FatSidebarItem {
50
77
}
51
78
52
79
override func mouseExited( with event: NSEvent ) {
80
+ mouseDidExit ( )
81
+ }
82
+
83
+ /// - note: Use when event is not available, as in `updateTrackingRect`.
84
+ fileprivate func mouseDidExit( ) {
53
85
86
+ didExit = true // Call before endHover to prevend updateTrackingRect loop
54
87
endHover ( )
55
88
}
56
89
0 commit comments