4
votes

There is a NSView on top of NSTextView, and the range of NSTextview is larger than the NSView range.

NSView has some of the above NSButton and so on, work very well, but the mouse style makes me a bit puzzled.

I think that when the mouse moves to NSView, it has been a arrow style, but not, it always displays the iBeam style.

Because it's on the NSTextView, so when my mouse moves to NSView, it shows the iBeam style. I change mouse NSCursor.arrow.set in real time by override func mouseMoved (with event: NSEvent), though it is okay, I find it will flash and occasionally show iBeam.

Is it the problem of the layer? Or what I should do is better, at least not flickering.

I looked at some questions, but they didn't answer this question very well, so I recount this question again, and hope to get the exact answer.

1
Is the text view editable and/or selectable?Willeke
@Willeke Yes, NSView is in the editing range of NSTextView. I hope that selectable does not need to be modified to false, because that will lose the NSTextView "in edit" style.Simon
I'm not exactly clear on what you're trying to accomplish, but have you just tried using -addCursorRect:cursor: on the NSView?James Bucanek
@JamesBucanek I tried it, but it didn't work.Simon

1 Answers

2
votes

The NSTextView resets the mouse cursor in it's mouseMoved: event.

If you own the NSTextView, you can subclass it and override mouseMoved:. This answer has some great examples.

If that's not an option for you, you will need to put your NSView (the one that's over the text field) in a transparent, borderless NSWindow. Then position and keep the window in place by making it a child window. See this answer for the methodology.