Improve loads of fancy things in relation to the mouse pointer

This commit is contained in:
2026-10-07 13:02:52 +02:00
parent ed5a227c9d
commit a0b3ef9975
25 changed files with 334 additions and 89 deletions
@@ -36,10 +36,20 @@ class PointerBoundTextView: NSTextView, PointerTextTarget {
addPointerCursorRect(visibleRectWithoutScrollers)
}
/// NSTextView's own `mouseMoved` sets the I-beam, so it runs only where the policy gives the I-beam;
/// under an overlay it would flip the pointer to the I-beam and back on every move.
override func mouseMoved(with event: NSEvent) {
guard let point = mouseLocation, isTopmost(atWindowPoint: point) else { return }
super.mouseMoved(with: event)
applyPointer(pointerShape(isOverText: true), atWindowPoint: point)
let shape = pointerShape(isOverText: true)
if shape == .iBeam { super.mouseMoved(with: event) }
applyPointer(shape, atWindowPoint: point)
}
/// NSTextView's `mouseEntered` sets the I-beam itself, so it runs only where the policy allows the I-beam.
override func mouseEntered(with event: NSEvent) {
if allowsIBeamRect { super.mouseEntered(with: event) }
guard let window, !PointerPolicy.isSelecting else { return }
PointerPolicy.updateCursor(in: window)
}
/// An update meant for another view is handed to the view under the mouse.
@@ -73,6 +83,8 @@ class PointerBoundTextView: NSTextView, PointerTextTarget {
super.viewDidMoveToSuperview()
NotificationCenter.default.removeObserver(self, name: NSView.frameDidChangeNotification, object: nil)
guard let clip = superview as? NSClipView else { return }
// NSTextView gives its clip view an I-beam document cursor, whose rect would bypass the policy under an overlay.
clip.documentCursor = nil
clip.postsFrameChangedNotifications = true
NotificationCenter.default.addObserver(self, selector: #selector(clipFrameChanged), name: NSView.frameDidChangeNotification,
object: clip)