I am setting up an NSTrackingArea for a specific part of my NSTextView in order to have the mouseMoved etc methods only to be fired when inside this rect. Here is my code:
let rect = ...
let ta = NSTrackingArea(rect: rect,
options: [.mouseEnteredAndExited, .mouseMoved, .activeWhenFirstResponder, .inVisibleRect],
owner: self,
userInfo: nil)
addTrackingArea(ta)
However, mouseMoved et al. are fired for the whole view.
So my question is: why is mouseMoved fired when the mouse is outside of the tracking area? Is there a mistake in the code above?
EDIT:
Apparently, somewhere, a trackingArea is added for the whole view, as I can see in the debug panel:
[NSTrackingArea 0x60000212a3f0: rect={{0, 0}, {800, 319.5}}, owner=0x60000390da00 userData=(null)
NSTrackingMouseEnteredAndExited NSTrackingMouseMoved
NSTrackingActiveWhenFirstResponder
NSTrackingInVisibleRect
installed enabled ]
Removing super.updateTrackingAreas() does not change this, so something else is going on. I can remove it by using trackingAreas.forEach { if $0.rect == self.bounds { removeTrackingArea($0)} }, but it seems to added back when mouseMoved: is fired (see the comments).