I need to create a popover when a users hovers over a particular word in NSTextView e.g
"The boy owns a dog"
Once the user has the cursor over a dog (mouse up with nothing selected), a cocoa event needs to fire so i can perform an action, which is show a popover my case
I thought NSAttributedString might be able to help, but don't see any hover events or tracking ability built in.
The possible solution is by using
NSTextAttachmentandattachmentCellproperty.So here is a way
subclass your custom cell from
NSTextAttachmentCell, so you have access to overridewantsToTrackMouse,highlight...andtrackMouse...interfacescreate empty
NSTextAttachment(if needed it can also be subclassed) and set your instance of cell toattachmentCelladd above text attachment to your NSTextStorage (mutable attributed string) in desired word's range with
NSAttributedString.Key.attachment