I had some time to play around with #AppKit to figure out a fix to the problem. #dev #macOS #SwiftUI **Recap of the problem:** When I have an overlay above an `NSTextView`, I don't want the iBeam cursor to show when hovering the overlay. But it will actually change to iBeam because the `NSTextView` is below and it just has higher priority, so it will override the cursor. This does not have a straightforward fix, so I had to figure it out on my own... It was not as simple as I thought. I did end up using both `resetCursorRects()` and `addCursorRect()` as I anticipated, but that alone was not enough... I also had to override `mouseEntered()` in the `NSTextView` to block it from changing `NSCursor` to iBeam whenever `hitView` is true. It would flicker to iBeam when hitting the edge of a text view. By overriding `mouseEntered()` in the text view, I could explicitly tell it NOT to do it by blocking the `NSEvent`. I did the same for `mouseMoved()` and `mouseExited()`. The `hitView` is whatever SwiftUI element I have assigned with `.background(ArrowCursorView())`. After testing, this seems to work perfectly, except for ONE thing ๐Ÿ˜ฉ It will not allow showing the iBeam in the search field I have inside the overlay (it also gets overridden), so that will be the next task to solve ๐Ÿ˜
Frederik Handberg's avatar Frederik Handberg
I probably need to call the super keyword on `resetCursorRects()` to inherit the default cursor functionality and then use `addCursorRect(bounds, cursor: .arrow)` to register the area where the cursor should be an arrow. https://developer.apple.com/documentation/appkit/nsview/resetcursorrects() https://developer.apple.com/documentation/appkit/nsview/addcursorrect(_:cursor:)
View quoted note →

Replies (1)

The nice thing about working on this "low level" stuff is that it gives a good deep understanding of AppKit. But ngl, it is pretty frustrating ๐Ÿ˜‚
โ†‘