Improve loads of fancy things in relation to the mouse pointer
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -93,10 +93,13 @@ extension NSView {
|
||||
hitView(atWindowPoint: point)?.isDescendant(of: self) ?? false
|
||||
}
|
||||
|
||||
/// The visible rect minus the enclosing scroll view's scrollers, which keep the arrow.
|
||||
/// The visible rect minus the enclosing scroll view's scrollers and line-number ruler, which keep the arrow.
|
||||
/// The clip view runs under a visible ruler, so the visible rect alone would give the gutter the I-beam.
|
||||
var visibleRectWithoutScrollers: NSRect {
|
||||
let scrollers = [enclosingScrollView?.verticalScroller, enclosingScrollView?.horizontalScroller]
|
||||
return scrollers.compactMap { $0 }.filter { !$0.isHidden && $0.superview != nil }
|
||||
let scroll = enclosingScrollView
|
||||
let ruler: NSView? = scroll?.rulersVisible == true ? scroll?.verticalRulerView : nil
|
||||
let strips: [NSView?] = [scroll?.verticalScroller, scroll?.horizontalScroller, ruler]
|
||||
return strips.compactMap { $0 }.filter { !$0.isHidden && $0.superview != nil }
|
||||
.reduce(visibleRect) { $0.removing(convert($1.bounds, from: $1)) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user