The last problem has been fixed. Now the iBeam cursor will show when hovering either an `NSTextField` or `NSTextView` inside the overlay. But it will not show the iBeam when hovering a text view that is behind the overlay - which is the expected behavior. It's really nice because I now have this `ArrowCursorView()` that I can call throughout my app wherever I am using an overlay. For example, I have a fullscreen search overlay where I also have this cursor problem. Now I can fix it by just calling `.background(ArrowCursorView())` on the overlay.
Frederik Handberg's avatar Frederik Handberg
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 ๐Ÿ˜ View quoted note โ†’
View quoted note →
โ†‘