cursor
This commit is contained in:
@@ -72,6 +72,7 @@ private struct GroupButton: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.onHover { isHovered = $0 }
|
.onHover { isHovered = $0 }
|
||||||
.accessibilityAddTraits(isOn ? .isSelected : [])
|
.accessibilityAddTraits(isOn ? .isSelected : [])
|
||||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||||
@@ -122,6 +123,7 @@ public struct ToolbarIconButton: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.onHover { isHovered = $0 }
|
.onHover { isHovered = $0 }
|
||||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public struct PrimaryButtonStyle: ButtonStyle {
|
|||||||
.padding(.vertical, 6)
|
.padding(.vertical, 6)
|
||||||
.background(destructive ? Palette.amberDeep : Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
.background(destructive ? Palette.amberDeep : Palette.amber, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ private struct SecondaryButtonBody: View {
|
|||||||
.background(isHovered || configuration.isPressed ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
.background(isHovered || configuration.isPressed ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
.onHover { isHovered = $0 }
|
.onHover { isHovered = $0 }
|
||||||
.animation(Metrics.smallControlTransition, value: isHovered)
|
.animation(Metrics.smallControlTransition, value: isHovered)
|
||||||
}
|
}
|
||||||
@@ -84,6 +86,8 @@ extension View {
|
|||||||
|
|
||||||
/// Disabled is 40% opacity and nothing else: no recolouring.
|
/// Disabled is 40% opacity and nothing else: no recolouring.
|
||||||
public func disabledLook(_ isDisabled: Bool) -> some View {
|
public func disabledLook(_ isDisabled: Bool) -> some View {
|
||||||
opacity(isDisabled ? 0.4 : 1).allowsHitTesting(!isDisabled)
|
opacity(isDisabled ? 0.4 : 1)
|
||||||
|
.allowsHitTesting(!isDisabled)
|
||||||
|
.transformEnvironment(\.allowsPointerHand) { if isDisabled { $0 = false } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ public struct ContextMenuRow: View {
|
|||||||
Rectangle().fill(isHighlighted ? Palette.amber : .clear).frame(width: Metrics.accentRule)
|
Rectangle().fill(isHighlighted ? Palette.amber : .clear).frame(width: Metrics.accentRule)
|
||||||
}
|
}
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var labelColor: Color {
|
private var labelColor: Color {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class PointerBoundTextView: NSTextView, PointerTextTarget {
|
|||||||
override func mouseEntered(with event: NSEvent) {
|
override func mouseEntered(with event: NSEvent) {
|
||||||
if allowsIBeamRect { super.mouseEntered(with: event) }
|
if allowsIBeamRect { super.mouseEntered(with: event) }
|
||||||
guard let window, !PointerPolicy.isSelecting else { return }
|
guard let window, !PointerPolicy.isSelecting else { return }
|
||||||
PointerPolicy.updateCursor(in: window)
|
PointerPolicy.scheduleUpdate(in: window)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An update meant for another view is handed to the view under the mouse.
|
/// An update meant for another view is handed to the view under the mouse.
|
||||||
@@ -58,7 +58,7 @@ class PointerBoundTextView: NSTextView, PointerTextTarget {
|
|||||||
if PointerPolicy.isSelecting || isTopmost(atWindowPoint: point) {
|
if PointerPolicy.isSelecting || isTopmost(atWindowPoint: point) {
|
||||||
updatePointer(atWindowPoint: point)
|
updatePointer(atWindowPoint: point)
|
||||||
} else {
|
} else {
|
||||||
PointerPolicy.updateCursor(in: window)
|
PointerPolicy.scheduleUpdate(in: window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import AppKit
|
import AppKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
/// The two pointers the rule picks between. A view may add its own extra on top: ⌘'s pointing hand, a splitter's resize.
|
/// The pointers the rule picks between. A view may add its own extra on top: ⌘'s pointing hand, a splitter's resize.
|
||||||
enum PointerShape: Equatable {
|
enum PointerShape: Equatable {
|
||||||
case iBeam
|
case iBeam
|
||||||
case arrow
|
case arrow
|
||||||
|
case pointingHand
|
||||||
|
|
||||||
var cursor: NSCursor { self == .iBeam ? .iBeam : .arrow }
|
var cursor: NSCursor {
|
||||||
|
switch self {
|
||||||
|
case .iBeam: .iBeam
|
||||||
|
case .arrow: .arrow
|
||||||
|
case .pointingHand: .pointingHand
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where a text-capable view lives: in a column, or in the open overlay.
|
/// Where a text-capable or clickable view lives: in a column, or in the open overlay.
|
||||||
enum PointerLayer: Equatable {
|
enum PointerLayer: Equatable, Sendable {
|
||||||
case workspace
|
case workspace
|
||||||
case overlay
|
case overlay
|
||||||
}
|
}
|
||||||
@@ -27,12 +34,25 @@ struct PointerState: Equatable {
|
|||||||
var isSelecting: Bool
|
var isSelecting: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The one pointer rule: the I-beam only where a single click places a caret or starts a text selection.
|
/// The one pointer rule: the I-beam only where a single click places a caret or starts a text selection,
|
||||||
|
/// the pointing hand only where a left click runs an action, the arrow everywhere else.
|
||||||
enum PointerPolicy {
|
enum PointerPolicy {
|
||||||
static func shape(_ state: PointerState) -> PointerShape {
|
static func shape(_ state: PointerState) -> PointerShape {
|
||||||
if state.isSelecting { return .iBeam }
|
if state.isSelecting { return .iBeam }
|
||||||
guard state.isEnabled, state.isOverText else { return .arrow }
|
guard state.isEnabled, state.isOverText, !isBehindOverlay(state.layer, overlayOpen: state.overlayOpen) else { return .arrow }
|
||||||
return state.overlayOpen && state.layer == .workspace ? .arrow : .iBeam
|
return .iBeam
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The pointer over a view that runs an action on a left click: a button, a clickable row.
|
||||||
|
static func shape(forClickable layer: PointerLayer, overlayOpen: Bool, isEnabled: Bool, isSelecting: Bool = false) -> PointerShape {
|
||||||
|
if isSelecting { return .iBeam }
|
||||||
|
guard isEnabled, !isBehindOverlay(layer, overlayOpen: overlayOpen) else { return .arrow }
|
||||||
|
return .pointingHand
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An open overlay takes the pointer from every column behind it.
|
||||||
|
static func isBehindOverlay(_ layer: PointerLayer, overlayOpen: Bool) -> Bool {
|
||||||
|
overlayOpen && layer == .workspace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +95,7 @@ extension PointerTextTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addPointerCursorRect(_ rect: NSRect) {
|
func addPointerCursorRect(_ rect: NSRect) {
|
||||||
guard allowsIBeamRect else { return }
|
guard rect.isUsableCursorRect, allowsIBeamRect else { return }
|
||||||
addCursorRect(rect, cursor: .iBeam)
|
addCursorRect(rect, cursor: .iBeam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +103,7 @@ extension PointerTextTarget {
|
|||||||
extension NSView {
|
extension NSView {
|
||||||
/// The view a click at the window point would reach, when the point lies in this view's visible part.
|
/// The view a click at the window point would reach, when the point lies in this view's visible part.
|
||||||
func hitView(atWindowPoint point: NSPoint) -> NSView? {
|
func hitView(atWindowPoint point: NSPoint) -> NSView? {
|
||||||
guard let window, let content = window.contentView, visibleRect.contains(convert(point, from: nil)) else { return nil }
|
guard let window, let content = window.contentView, visibleBounds.contains(convert(point, from: nil)) else { return nil }
|
||||||
return content.hitTest(content.superview?.convert(point, from: nil) ?? point)
|
return content.hitTest(content.superview?.convert(point, from: nil) ?? point)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +113,13 @@ extension NSView {
|
|||||||
hitView(atWindowPoint: point)?.isDescendant(of: self) ?? false
|
hitView(atWindowPoint: point)?.isDescendant(of: self) ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The visible rect within the view's own bounds. SwiftUI's platform-view host does not clip,
|
||||||
|
/// so a hosted view's visible rect alone can span the whole window.
|
||||||
|
var visibleBounds: NSRect {
|
||||||
|
let rect = visibleRect.intersection(bounds)
|
||||||
|
return rect.isUsableCursorRect ? rect : .zero
|
||||||
|
}
|
||||||
|
|
||||||
/// The visible rect minus the enclosing scroll view's scrollers and line-number ruler, 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.
|
/// The clip view runs under a visible ruler, so the visible rect alone would give the gutter the I-beam.
|
||||||
var visibleRectWithoutScrollers: NSRect {
|
var visibleRectWithoutScrollers: NSRect {
|
||||||
@@ -100,15 +127,42 @@ extension NSView {
|
|||||||
let ruler: NSView? = scroll?.rulersVisible == true ? scroll?.verticalRulerView : nil
|
let ruler: NSView? = scroll?.rulersVisible == true ? scroll?.verticalRulerView : nil
|
||||||
let strips: [NSView?] = [scroll?.verticalScroller, scroll?.horizontalScroller, ruler]
|
let strips: [NSView?] = [scroll?.verticalScroller, scroll?.horizontalScroller, ruler]
|
||||||
return strips.compactMap { $0 }.filter { !$0.isHidden && $0.superview != nil }
|
return strips.compactMap { $0 }.filter { !$0.isHidden && $0.superview != nil }
|
||||||
.reduce(visibleRect) { $0.removing(convert($1.bounds, from: $1)) }
|
.reduce(visibleBounds) { $0.removing(convert($1.bounds, from: $1)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension NSView {
|
||||||
|
fileprivate var enclosingClipView: NSClipView? {
|
||||||
|
var view = superview
|
||||||
|
while let current = view {
|
||||||
|
if let clip = current as? NSClipView { return clip }
|
||||||
|
view = current.superview
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate var isInScroller: Bool {
|
||||||
|
var view: NSView? = self
|
||||||
|
while let current = view {
|
||||||
|
if current is NSScroller { return true }
|
||||||
|
view = current.superview
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension NSRect {
|
extension NSRect {
|
||||||
|
/// False for an empty rect and for the null rect a missed intersection gives, whose origin is infinite;
|
||||||
|
/// `addCursorRect` raises on a non-finite rect.
|
||||||
|
var isUsableCursorRect: Bool {
|
||||||
|
!isNull && !isEmpty && origin.x.isFinite && origin.y.isFinite && size.width.isFinite && size.height.isFinite
|
||||||
|
}
|
||||||
|
|
||||||
/// The rect minus a strip that spans its full height or width along one edge, such as a scroller.
|
/// The rect minus a strip that spans its full height or width along one edge, such as a scroller.
|
||||||
func removing(_ strip: NSRect) -> NSRect {
|
func removing(_ strip: NSRect) -> NSRect {
|
||||||
|
guard isUsableCursorRect else { return .zero }
|
||||||
let overlap = intersection(strip)
|
let overlap = intersection(strip)
|
||||||
guard !overlap.isEmpty else { return self }
|
guard overlap.isUsableCursorRect else { return self }
|
||||||
var rest = self
|
var rest = self
|
||||||
if overlap.height >= height {
|
if overlap.height >= height {
|
||||||
rest.origin.x = overlap.minX > minX ? minX : overlap.maxX
|
rest.origin.x = overlap.minX > minX ? minX : overlap.maxX
|
||||||
@@ -139,7 +193,7 @@ extension PointerPolicy {
|
|||||||
|
|
||||||
static func endSelection(in window: NSWindow?) {
|
static func endSelection(in window: NSWindow?) {
|
||||||
selectionDrag = false
|
selectionDrag = false
|
||||||
if let window { updateCursor(in: window) }
|
scheduleUpdate(in: window)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func isOverlayOpen(in window: NSWindow?) -> Bool {
|
static func isOverlayOpen(in window: NSWindow?) -> Bool {
|
||||||
@@ -170,8 +224,39 @@ extension PointerPolicy {
|
|||||||
updateCursor(in: window)
|
updateCursor(in: window)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asks the view under the mouse for its pointer; anything that is not text gets the arrow.
|
private static var cursorUpdateMonitor: Any?
|
||||||
/// Views call this from `cursorUpdate`, so a nested call returns at once.
|
private static var pendingUpdate: Set<Int> = []
|
||||||
|
|
||||||
|
/// Answers every cursor update and mouse move in a key window through `scheduleUpdate`. It swallows the cursor update:
|
||||||
|
/// AppKit hands it to the hit view, and over a region view, which takes no clicks, the hosting view sets the arrow.
|
||||||
|
/// Mouse moves pass on untouched; they cover views whose tracking areas AppKit never fires, such as an overlay's field.
|
||||||
|
static func installCursorUpdateMonitor() {
|
||||||
|
guard cursorUpdateMonitor == nil else { return }
|
||||||
|
cursorUpdateMonitor = NSEvent.addLocalMonitorForEvents(matching: [.cursorUpdate, .mouseMoved]) { event in
|
||||||
|
let swallow = MainActor.assumeIsolated {
|
||||||
|
guard let window = event.window, window.isKeyWindow, window.areCursorRectsEnabled, !isSelecting else { return false }
|
||||||
|
scheduleUpdate(in: window)
|
||||||
|
return event.type == .cursorUpdate
|
||||||
|
}
|
||||||
|
return swallow ? nil : event
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Runs `updateCursor` once, after the current event. Inside an event SwiftUI's hit test returns its root view,
|
||||||
|
/// not the view under the mouse. It never resets the cursor rects: that would fire new cursor updates.
|
||||||
|
static func scheduleUpdate(in window: NSWindow?) {
|
||||||
|
guard let number = window?.windowNumber, pendingUpdate.insert(number).inserted else { return }
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
MainActor.assumeIsolated {
|
||||||
|
pendingUpdate.remove(number)
|
||||||
|
guard let window = NSApp.window(withWindowNumber: number) else { return }
|
||||||
|
updateCursor(in: window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asks the view under the mouse for its pointer; anything that is not text or clickable gets the arrow.
|
||||||
|
/// Call it outside an event (`scheduleUpdate`); a nested call returns at once.
|
||||||
static func updateCursor(in window: NSWindow) {
|
static func updateCursor(in window: NSWindow) {
|
||||||
guard !isUpdatingCursor, window.isKeyWindow, window.areCursorRectsEnabled, !isSelecting,
|
guard !isUpdatingCursor, window.isKeyWindow, window.areCursorRectsEnabled, !isSelecting,
|
||||||
let content = window.contentView else { return }
|
let content = window.contentView else { return }
|
||||||
@@ -180,56 +265,93 @@ extension PointerPolicy {
|
|||||||
let point = window.mouseLocationOutsideOfEventStream
|
let point = window.mouseLocationOutsideOfEventStream
|
||||||
guard content.bounds.contains(content.convert(point, from: nil)),
|
guard content.bounds.contains(content.convert(point, from: nil)),
|
||||||
NSWindow.windowNumber(at: NSEvent.mouseLocation, belowWindowWithWindowNumber: 0) == window.windowNumber else { return }
|
NSWindow.windowNumber(at: NSEvent.mouseLocation, belowWindowWithWindowNumber: 0) == window.windowNumber else { return }
|
||||||
|
let overlayOpen = isOverlayOpen(in: window)
|
||||||
let hit = content.hitTest(content.superview?.convert(point, from: nil) ?? point)
|
let hit = content.hitTest(content.superview?.convert(point, from: nil) ?? point)
|
||||||
var view = hit
|
var view = hit
|
||||||
while let current = view {
|
while let current = view {
|
||||||
if let owner = current as? PointerOwner {
|
if let owner = current as? PointerOwner {
|
||||||
|
// A column's text view under the open overlay yields to the overlay's own regions.
|
||||||
|
let behind = (owner as? PointerTextTarget).map { isBehindOverlay($0.pointerLayer, overlayOpen: overlayOpen) } ?? false
|
||||||
|
if !behind {
|
||||||
owner.updatePointer(atWindowPoint: point)
|
owner.updatePointer(atWindowPoint: point)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
view = current.superview
|
view = current.superview
|
||||||
}
|
}
|
||||||
if let hit, let region = textRegion(in: content, at: point, under: hit) {
|
if let hit, let region = region(in: content, at: point, under: hit, overlayOpen: overlayOpen) {
|
||||||
region.updatePointer(atWindowPoint: point)
|
region.updatePointer(atWindowPoint: point)
|
||||||
} else {
|
} else {
|
||||||
NSCursor.arrow.set()
|
NSCursor.arrow.set()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A region counts only when the click would land on its own hosting or scroll view, not on a scroller or another view.
|
/// The topmost region under the point; with an overlay open, the overlay's regions come first.
|
||||||
private static func textRegion(in view: NSView, at point: NSPoint, under hit: NSView) -> PointerTextRegionView? {
|
/// A column region counts when the hit view lies in its scroll view or in none, and never over a scroller.
|
||||||
if let region = view as? PointerTextRegionView, !region.isHiddenOrHasHiddenAncestor, region.isDescendant(of: hit),
|
private static func region(in content: NSView, at point: NSPoint, under hit: NSView, overlayOpen: Bool) -> PointerRegionView? {
|
||||||
region.isPointerOverText(atWindowPoint: point) { return region }
|
guard !hit.isInScroller else { return nil }
|
||||||
|
var found: [PointerRegionView] = []
|
||||||
|
collectRegions(in: content, at: point, into: &found)
|
||||||
|
// SwiftUI spreads a scroll view's platform views over several containers, and while it rebuilds a row
|
||||||
|
// the hit view is its root graphics view, so a region need not sit under the hit view.
|
||||||
|
let clip = hit.enclosingClipView
|
||||||
|
let reachable = found.filter { region in
|
||||||
|
clip == nil || region.enclosingClipView === clip || (overlayOpen && region.pointerLayer == .overlay)
|
||||||
|
}
|
||||||
|
let overlayRegions = overlayOpen ? reachable.filter { $0.pointerLayer == .overlay } : []
|
||||||
|
return (overlayRegions.isEmpty ? reachable : overlayRegions).last
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Skips hidden subtrees only: SwiftUI's hosts do not clip, so a region may lie outside its ancestors' frames.
|
||||||
|
private static func collectRegions(in view: NSView, at point: NSPoint, into found: inout [PointerRegionView]) {
|
||||||
|
guard !view.isHidden else { return }
|
||||||
|
if let region = view as? PointerRegionView, region.isPointerOverRegion(atWindowPoint: point) {
|
||||||
|
found.append(region)
|
||||||
|
}
|
||||||
for subview in view.subviews {
|
for subview in view.subviews {
|
||||||
if let region = textRegion(in: subview, at: point, under: hit) { return region }
|
collectRegions(in: subview, at: point, into: &found)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - SwiftUI text
|
// MARK: - SwiftUI regions
|
||||||
|
|
||||||
/// Gives SwiftUI text that selects on click, such as the Markdown preview, the policy's I-beam. It takes no clicks.
|
/// A SwiftUI-placed view that only marks an area for the pointer. It takes no clicks.
|
||||||
struct PointerTextRegion: NSViewRepresentable {
|
class PointerRegionView: NSView, PointerOwner {
|
||||||
func makeNSView(context: Context) -> PointerTextRegionView {
|
var pointerLayer = PointerLayer.workspace {
|
||||||
PointerTextRegionView()
|
didSet { if pointerLayer != oldValue { pointerChanged() } }
|
||||||
}
|
}
|
||||||
|
private lazy var tracker = PointerTracker(view: self)
|
||||||
func updateNSView(_ view: PointerTextRegionView, context: Context) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class PointerTextRegionView: NSView, PointerTextTarget {
|
|
||||||
let pointerLayer = PointerLayer.workspace
|
|
||||||
var acceptsPointerText: Bool { true }
|
|
||||||
|
|
||||||
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
override func hitTest(_ point: NSPoint) -> NSView? { nil }
|
||||||
|
|
||||||
func isPointerOverText(atWindowPoint point: NSPoint) -> Bool {
|
override func updateTrackingAreas() {
|
||||||
|
super.updateTrackingAreas()
|
||||||
|
tracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func setFrameOrigin(_ newOrigin: NSPoint) {
|
||||||
|
super.setFrameOrigin(newOrigin)
|
||||||
|
tracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func setFrameSize(_ newSize: NSSize) {
|
||||||
|
super.setFrameSize(newSize)
|
||||||
|
tracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
func isPointerOverRegion(atWindowPoint point: NSPoint) -> Bool {
|
||||||
visibleRectWithoutScrollers.contains(convert(point, from: nil))
|
visibleRectWithoutScrollers.contains(convert(point, from: nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
override func resetCursorRects() {
|
func updatePointer(atWindowPoint point: NSPoint) {
|
||||||
addPointerCursorRect(visibleRectWithoutScrollers)
|
NSCursor.arrow.set()
|
||||||
|
}
|
||||||
|
|
||||||
|
func pointerChanged() {
|
||||||
|
window?.invalidateCursorRects(for: self)
|
||||||
|
PointerPolicy.setNeedsRefresh(in: window)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidMoveToWindow() {
|
override func viewDidMoveToWindow() {
|
||||||
@@ -242,3 +364,125 @@ final class PointerTextRegionView: NSView, PointerTextTarget {
|
|||||||
super.viewWillMove(toWindow: newWindow)
|
super.viewWillMove(toWindow: newWindow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Re-reads the pointer whenever the mouse enters or leaves a view or crosses into its cursor area.
|
||||||
|
/// A separate owner, because SwiftTerm's enter and exit handlers cannot be overridden.
|
||||||
|
final class PointerTracker: NSResponder {
|
||||||
|
private weak var view: NSView?
|
||||||
|
private var area: NSTrackingArea?
|
||||||
|
|
||||||
|
init(view: NSView) {
|
||||||
|
self.view = view
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("PointerTracker is built in code")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fits the tracking area to the view's visible part; call it from every `updateTrackingAreas` and frame change.
|
||||||
|
/// Not `.inVisibleRect`: in SwiftUI's non-clipping host the visible rect spans the window, so the mouse would never enter.
|
||||||
|
func update() {
|
||||||
|
guard let view else { return }
|
||||||
|
let rect = view.visibleBounds
|
||||||
|
// Re-added even when the rect is unchanged: an area added while its view was moving keeps a stale position.
|
||||||
|
if let area { view.removeTrackingArea(area) }
|
||||||
|
area = nil
|
||||||
|
guard rect.isUsableCursorRect else { return }
|
||||||
|
let area = NSTrackingArea(rect: rect, options: [.cursorUpdate, .mouseEnteredAndExited, .activeInKeyWindow], owner: self)
|
||||||
|
view.addTrackingArea(area)
|
||||||
|
self.area = area
|
||||||
|
}
|
||||||
|
|
||||||
|
override func mouseEntered(with event: NSEvent) { pointerMoved() }
|
||||||
|
override func mouseExited(with event: NSEvent) { pointerMoved() }
|
||||||
|
override func cursorUpdate(with event: NSEvent) { pointerMoved() }
|
||||||
|
|
||||||
|
private func pointerMoved() {
|
||||||
|
PointerPolicy.scheduleUpdate(in: view?.window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension EnvironmentValues {
|
||||||
|
/// The overlay host sets `.overlay`, so the regions inside it keep their pointer while the columns lose theirs.
|
||||||
|
@Entry var pointerLayer = PointerLayer.workspace
|
||||||
|
/// False under `disabledLook`, whose hit-testing switch SwiftUI does not expose.
|
||||||
|
@Entry var allowsPointerHand = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - SwiftUI text
|
||||||
|
|
||||||
|
/// Gives SwiftUI text that selects on click, such as the Markdown preview, the policy's I-beam. It takes no clicks.
|
||||||
|
struct PointerTextRegion: NSViewRepresentable {
|
||||||
|
func makeNSView(context: Context) -> PointerTextRegionView {
|
||||||
|
PointerTextRegionView()
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNSView(_ view: PointerTextRegionView, context: Context) {
|
||||||
|
view.pointerLayer = context.environment.pointerLayer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class PointerTextRegionView: PointerRegionView, PointerTextTarget {
|
||||||
|
var acceptsPointerText: Bool { true }
|
||||||
|
|
||||||
|
func isPointerOverText(atWindowPoint point: NSPoint) -> Bool {
|
||||||
|
isPointerOverRegion(atWindowPoint: point)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func updatePointer(atWindowPoint point: NSPoint) {
|
||||||
|
pointerShape(atWindowPoint: point).cursor.set()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func resetCursorRects() {
|
||||||
|
addPointerCursorRect(visibleRectWithoutScrollers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - SwiftUI clickables
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
/// Shows the pointing hand over this view; apply it to the exact view a left click acts on.
|
||||||
|
/// A `.disabled` or `disabledLook` ancestor turns it into the arrow.
|
||||||
|
func pointerHand(_ isEnabled: Bool = true) -> some View {
|
||||||
|
background(PointerHandRegion(isEnabled: isEnabled))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PointerHandRegion: NSViewRepresentable {
|
||||||
|
var isEnabled: Bool
|
||||||
|
|
||||||
|
func makeNSView(context: Context) -> PointerHandRegionView {
|
||||||
|
let view = PointerHandRegionView()
|
||||||
|
updateNSView(view, context: context)
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNSView(_ view: PointerHandRegionView, context: Context) {
|
||||||
|
let environment = context.environment
|
||||||
|
view.pointerLayer = environment.pointerLayer
|
||||||
|
view.isClickable = isEnabled && environment.isEnabled && environment.allowsPointerHand
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class PointerHandRegionView: PointerRegionView {
|
||||||
|
var isClickable = true {
|
||||||
|
didSet { if isClickable != oldValue { pointerChanged() } }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func shape(isSelecting: Bool) -> PointerShape {
|
||||||
|
PointerPolicy.shape(forClickable: pointerLayer, overlayOpen: PointerPolicy.isOverlayOpen(in: window),
|
||||||
|
isEnabled: isClickable, isSelecting: isSelecting)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func updatePointer(atWindowPoint point: NSPoint) {
|
||||||
|
shape(isSelecting: PointerPolicy.isSelecting).cursor.set()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cursor rects ignore an overlay on top, so the hand rect exists only while the rule allows it.
|
||||||
|
override func resetCursorRects() {
|
||||||
|
let rect = visibleRectWithoutScrollers
|
||||||
|
guard rect.isUsableCursorRect, shape(isSelecting: false) == .pointingHand else { return }
|
||||||
|
addCursorRect(rect, cursor: .pointingHand)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public struct SegmentButton: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.fixedSize()
|
.fixedSize()
|
||||||
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ final class SplitterHandleView: NSView, PointerOwner {
|
|||||||
if inside {
|
if inside {
|
||||||
cursor.set()
|
cursor.set()
|
||||||
} else if let window {
|
} else if let window {
|
||||||
PointerPolicy.updateCursor(in: window)
|
PointerPolicy.scheduleUpdate(in: window)
|
||||||
}
|
}
|
||||||
onHover(inside)
|
onHover(inside)
|
||||||
onEnd()
|
onEnd()
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ private struct CollapseButton: View {
|
|||||||
.background(hovering ? Palette.hover : Color.clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
.background(hovering ? Palette.hover : Color.clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
|
||||||
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).stroke(Palette.raised, lineWidth: Metrics.hairline))
|
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).stroke(Palette.raised, lineWidth: Metrics.hairline))
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture(perform: action)
|
.onTapGesture(perform: action)
|
||||||
.onHover { hovering = $0 }
|
.onHover { hovering = $0 }
|
||||||
.animation(Metrics.colorTransition, value: hovering)
|
.animation(Metrics.colorTransition, value: hovering)
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ struct SymbolPopupView: View {
|
|||||||
}
|
}
|
||||||
.id(index)
|
.id(index)
|
||||||
.onHover { if $0 { highlighted = index } }
|
.onHover { if $0 { highlighted = index } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(SymbolTarget(path: def.path, line: def.line)) }
|
.onTapGesture { open(SymbolTarget(path: def.path, line: def.line)) }
|
||||||
}
|
}
|
||||||
ForEach(Array(lookup.definitions.enumerated()), id: \.offset) { _, def in relations(def) }
|
ForEach(Array(lookup.definitions.enumerated()), id: \.offset) { _, def in relations(def) }
|
||||||
@@ -133,6 +134,7 @@ struct SymbolPopupView: View {
|
|||||||
.padding(.top, 8)
|
.padding(.top, 8)
|
||||||
.padding(.bottom, 2)
|
.padding(.bottom, 2)
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { if let first = group.hits.first { open(SymbolTarget(path: group.path, line: first.line)) } }
|
.onTapGesture { if let first = group.hits.first { open(SymbolTarget(path: group.path, line: first.line)) } }
|
||||||
case let .hit(path, hit, index):
|
case let .hit(path, hit, index):
|
||||||
SymbolRow(isHighlighted: highlighted == index) {
|
SymbolRow(isHighlighted: highlighted == index) {
|
||||||
@@ -147,6 +149,7 @@ struct SymbolPopupView: View {
|
|||||||
}
|
}
|
||||||
.id(index)
|
.id(index)
|
||||||
.onHover { if $0 { highlighted = index } }
|
.onHover { if $0 { highlighted = index } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(SymbolTarget(path: path, line: hit.line)) }
|
.onTapGesture { open(SymbolTarget(path: path, line: hit.line)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,6 +247,7 @@ private struct SymbolChip: View {
|
|||||||
.overlay(RoundedRectangle(cornerRadius: 3).stroke(lit ? Palette.amberKeycapBorder : Palette.raised, lineWidth: Metrics.hairline))
|
.overlay(RoundedRectangle(cornerRadius: 3).stroke(lit ? Palette.amberKeycapBorder : Palette.raised, lineWidth: Metrics.hairline))
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
.onHover { hovering = $0 }
|
.onHover { hovering = $0 }
|
||||||
|
.pointerHand(known)
|
||||||
.onTapGesture { if known { follow() } }
|
.onTapGesture { if known { follow() } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ private struct TreeRowView: View {
|
|||||||
.frame(height: Metrics.explorerRow)
|
.frame(height: Metrics.explorerRow)
|
||||||
.selectableRow(isSelected: selected, isHovered: hovered)
|
.selectableRow(isSelected: selected, isHovered: hovered)
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture(perform: onClick)
|
.onTapGesture(perform: onClick)
|
||||||
.onHover { inside in
|
.onHover { inside in
|
||||||
hovered = inside
|
hovered = inside
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ struct QuickActionButton: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.onHover { hovered = $0 }
|
.onHover { hovered = $0 }
|
||||||
.help(help)
|
.help(help)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ public struct OverlayHost: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
|
overlay.environment(\.pointerLayer, .overlay)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var overlay: some View {
|
||||||
switch model.overlay.current {
|
switch model.overlay.current {
|
||||||
case .none, .launcher:
|
case .none, .launcher:
|
||||||
EmptyView()
|
EmptyView()
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ final class CommandFieldBox: NSView, PointerTextTarget {
|
|||||||
let field: NSTextField
|
let field: NSTextField
|
||||||
let inset: CGFloat
|
let inset: CGFloat
|
||||||
let pointerLayer = PointerLayer.overlay
|
let pointerLayer = PointerLayer.overlay
|
||||||
|
private lazy var pointerTracker = PointerTracker(view: self)
|
||||||
|
|
||||||
init(field: NSTextField, inset: CGFloat) {
|
init(field: NSTextField, inset: CGFloat) {
|
||||||
self.field = field
|
self.field = field
|
||||||
@@ -137,6 +138,29 @@ final class CommandFieldBox: NSView, PointerTextTarget {
|
|||||||
addPointerCursorRect(bounds)
|
addPointerCursorRect(bounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cursor rects alone never fire inside the SwiftUI overlay, so entering the box re-reads the pointer.
|
||||||
|
override func updateTrackingAreas() {
|
||||||
|
super.updateTrackingAreas()
|
||||||
|
pointerTracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func setFrameOrigin(_ newOrigin: NSPoint) {
|
||||||
|
super.setFrameOrigin(newOrigin)
|
||||||
|
pointerTracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func setFrameSize(_ newSize: NSSize) {
|
||||||
|
super.setFrameSize(newSize)
|
||||||
|
pointerTracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A mouse already resting where the field appears gets no enter event, so the pointer is read once it is shown.
|
||||||
|
override func viewDidMoveToWindow() {
|
||||||
|
super.viewDidMoveToWindow()
|
||||||
|
pointerTracker.update()
|
||||||
|
PointerPolicy.scheduleUpdate(in: window)
|
||||||
|
}
|
||||||
|
|
||||||
override func mouseDown(with event: NSEvent) {
|
override func mouseDown(with event: NSEvent) {
|
||||||
guard field.currentEditor() == nil else { return }
|
guard field.currentEditor() == nil else { return }
|
||||||
window?.makeFirstResponder(field)
|
window?.makeFirstResponder(field)
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ struct RecentFilesOverlay: View {
|
|||||||
row(path, selected: index == selection)
|
row(path, selected: index == selection)
|
||||||
.id(index)
|
.id(index)
|
||||||
.onHover { inside in if inside { hover(index) } }
|
.onHover { inside in if inside { hover(index) } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(path) }
|
.onTapGesture { open(path) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ struct SearchOverlay: View {
|
|||||||
.strokeBorder(on ? Palette.amber : Palette.raised, lineWidth: Metrics.hairline))
|
.strokeBorder(on ? Palette.amber : Palette.raised, lineWidth: Metrics.hairline))
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.tip(SearchModel.chipTooltip(count: chip.count, isChosen: model.extensionFilter == chip.ext))
|
.tip(SearchModel.chipTooltip(count: chip.count, isChosen: model.extensionFilter == chip.ext))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,6 +152,7 @@ struct SearchOverlay: View {
|
|||||||
hitLine(hit, selected: selected)
|
hitLine(hit, selected: selected)
|
||||||
.id(index)
|
.id(index)
|
||||||
.onHover { inside in if inside { hover(.thisFile, row: index) } }
|
.onHover { inside in if inside { hover(.thisFile, row: index) } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(SearchModel.Target(path: path, line: hit.line)) }
|
.onTapGesture { open(SearchModel.Target(path: path, line: hit.line)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,6 +176,7 @@ struct SearchOverlay: View {
|
|||||||
let selected = model.column == .project && model.projectSelection == row.index
|
let selected = model.column == .project && model.projectSelection == row.index
|
||||||
hitLine(row.hit, selected: selected)
|
hitLine(row.hit, selected: selected)
|
||||||
.onHover { inside in if inside { hover(.project, row: row.index) } }
|
.onHover { inside in if inside { hover(.project, row: row.index) } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(SearchModel.Target(path: row.path, line: row.hit.line)) }
|
.onTapGesture { open(SearchModel.Target(path: row.path, line: row.hit.line)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,6 +208,7 @@ struct SearchOverlay: View {
|
|||||||
.onHover { inside in
|
.onHover { inside in
|
||||||
if inside { hoveredGroup = group.path } else if hoveredGroup == group.path { hoveredGroup = nil }
|
if inside { hoveredGroup = group.path } else if hoveredGroup == group.path { hoveredGroup = nil }
|
||||||
}
|
}
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
if let first = group.rows.first { open(SearchModel.Target(path: group.path, line: first.hit.line)) }
|
if let first = group.rows.first { open(SearchModel.Target(path: group.path, line: first.hit.line)) }
|
||||||
}
|
}
|
||||||
@@ -241,6 +245,7 @@ struct SearchOverlay: View {
|
|||||||
let selected = model.column == .files && model.fileSelection == index
|
let selected = model.column == .files && model.fileSelection == index
|
||||||
fileRow(match, selected: selected)
|
fileRow(match, selected: selected)
|
||||||
.onHover { inside in if inside { hover(.files, row: index) } }
|
.onHover { inside in if inside { hover(.files, row: index) } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(SearchModel.Target(path: match.path, line: nil)) }
|
.onTapGesture { open(SearchModel.Target(path: match.path, line: nil)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func applicationDidFinishLaunching(_ notification: Notification) {
|
public func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
|
PointerPolicy.installCursorUpdateMonitor()
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ private struct LauncherRow<Icon: View, Label: View, Trailing: View>: View {
|
|||||||
isHovered = inside
|
isHovered = inside
|
||||||
if inside { model.perform(.launcherSelect(index)) }
|
if inside { model.perform(.launcherSelect(index)) }
|
||||||
}
|
}
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
model.perform(.launcherSelect(index))
|
model.perform(.launcherSelect(index))
|
||||||
model.perform(.launcherActivate)
|
model.perform(.launcherActivate)
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ struct RecentProjectsOverlay: View {
|
|||||||
row(project, selected: index == selection)
|
row(project, selected: index == selection)
|
||||||
.id(index)
|
.id(index)
|
||||||
.onHover { inside in if inside { hover(index) } }
|
.onHover { inside in if inside { hover(index) } }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture { open(project) }
|
.onTapGesture { open(project) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ private struct ProjectName: View {
|
|||||||
.foregroundStyle(isHovered ? Palette.text2 : Palette.text4)
|
.foregroundStyle(isHovered ? Palette.text2 : Palette.text4)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
.onHover { isHovered = $0 }
|
.onHover { isHovered = $0 }
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture(perform: action)
|
.onTapGesture(perform: action)
|
||||||
.help("Open folder…")
|
.help("Open folder…")
|
||||||
.animation(Metrics.colorTransition, value: isHovered)
|
.animation(Metrics.colorTransition, value: isHovered)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ struct WorkspaceView: View {
|
|||||||
}
|
}
|
||||||
.overlay { OverlayHost(model: model) }
|
.overlay { OverlayHost(model: model) }
|
||||||
.overlay {
|
.overlay {
|
||||||
if model.overlay.current == .launcher { RecentProjectsOverlay(model: model) }
|
if model.overlay.current == .launcher { RecentProjectsOverlay(model: model).environment(\.pointerLayer, .overlay) }
|
||||||
}
|
}
|
||||||
.background(PointerRefresher(trigger: PointerRefresher.Trigger(
|
.background(PointerRefresher(trigger: PointerRefresher.Trigger(
|
||||||
overlay: model.overlay.current, activePath: model.editor?.activePath, visibility: model.layout.visibility,
|
overlay: model.overlay.current, activePath: model.editor?.activePath, visibility: model.layout.visibility,
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ private struct CommitButton: View {
|
|||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.disabled(!isEnabled)
|
.disabled(!isEnabled)
|
||||||
.onHover { hovered = $0 }
|
.onHover { hovered = $0 }
|
||||||
.animation(Metrics.colorTransition, value: hovered)
|
.animation(Metrics.colorTransition, value: hovered)
|
||||||
@@ -117,6 +118,7 @@ private struct PushButton: View {
|
|||||||
.opacity(busy ? 0.4 : 1)
|
.opacity(busy ? 0.4 : 1)
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
|
.pointerHand()
|
||||||
.disabled(busy)
|
.disabled(busy)
|
||||||
.onHover { hovered = $0 }
|
.onHover { hovered = $0 }
|
||||||
.animation(Metrics.colorTransition, value: hovered)
|
.animation(Metrics.colorTransition, value: hovered)
|
||||||
|
|||||||
@@ -246,6 +246,7 @@ private struct GitRowView: View {
|
|||||||
.frame(height: Metrics.sourceControlRow)
|
.frame(height: Metrics.sourceControlRow)
|
||||||
.selectableRow(isSelected: selected, isHovered: hovered)
|
.selectableRow(isSelected: selected, isHovered: hovered)
|
||||||
.contentShape(Rectangle())
|
.contentShape(Rectangle())
|
||||||
|
.pointerHand()
|
||||||
.onTapGesture(perform: onOpen)
|
.onTapGesture(perform: onOpen)
|
||||||
.onHover { inside in
|
.onHover { inside in
|
||||||
hovered = inside
|
hovered = inside
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
|||||||
var appliedSettings: HelderConfig.Terminal?
|
var appliedSettings: HelderConfig.Terminal?
|
||||||
var appliedScale = 1.0
|
var appliedScale = 1.0
|
||||||
private var closeObserver: NSObjectProtocol?
|
private var closeObserver: NSObjectProtocol?
|
||||||
|
private lazy var pointerTracker = PointerTracker(view: self)
|
||||||
private let events = ProcessEvents()
|
private let events = ProcessEvents()
|
||||||
|
|
||||||
init(kind: TerminalKind, store: TerminalStore) {
|
init(kind: TerminalKind, store: TerminalStore) {
|
||||||
@@ -116,12 +117,21 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
|||||||
/// The first click in an inactive window already places the selection or reaches the program.
|
/// The first click in an inactive window already places the selection or reaches the program.
|
||||||
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
||||||
|
|
||||||
|
/// SwiftTerm's own tracking area has no cursor updates, so entering the grid would not re-read the pointer.
|
||||||
|
override func updateTrackingAreas() {
|
||||||
|
super.updateTrackingAreas()
|
||||||
|
pointerTracker.update()
|
||||||
|
}
|
||||||
|
|
||||||
/// SwiftTerm's `resetCursorRects` is not open, so its I-beam rect is filtered here and leaves out the scroller.
|
/// SwiftTerm's `resetCursorRects` is not open, so its I-beam rect is filtered here and leaves out the scroller.
|
||||||
override func addCursorRect(_ rect: NSRect, cursor object: NSCursor) {
|
override func addCursorRect(_ rect: NSRect, cursor object: NSCursor) {
|
||||||
|
guard rect.isUsableCursorRect else { return }
|
||||||
guard object == .iBeam else { return super.addCursorRect(rect, cursor: object) }
|
guard object == .iBeam else { return super.addCursorRect(rect, cursor: object) }
|
||||||
guard allowsIBeamRect else { return }
|
guard allowsIBeamRect else { return }
|
||||||
let scroller = subviews.first { $0 is NSScroller && !$0.isHidden }
|
let scroller = subviews.first { $0 is NSScroller && !$0.isHidden }
|
||||||
super.addCursorRect(scroller.map { rect.removing($0.frame) } ?? rect, cursor: object)
|
let area = scroller.map { rect.removing($0.frame) } ?? rect
|
||||||
|
guard area.isUsableCursorRect else { return }
|
||||||
|
super.addCursorRect(area, cursor: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gives this class its own `cursorUpdate:` that asks the policy; Swift cannot override SwiftTerm's I-beam one,
|
/// Gives this class its own `cursorUpdate:` that asks the policy; Swift cannot override SwiftTerm's I-beam one,
|
||||||
@@ -134,7 +144,7 @@ final class HelderTerminalView: LocalProcessTerminalView, TerminalSessionHandle,
|
|||||||
if PointerPolicy.isSelecting || view.isTopmost(atWindowPoint: point) {
|
if PointerPolicy.isSelecting || view.isTopmost(atWindowPoint: point) {
|
||||||
view.updatePointer(atWindowPoint: point)
|
view.updatePointer(atWindowPoint: point)
|
||||||
} else {
|
} else {
|
||||||
PointerPolicy.updateCursor(in: window)
|
PointerPolicy.scheduleUpdate(in: window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import AppKit
|
||||||
@testable import HelderUI
|
@testable import HelderUI
|
||||||
import Testing
|
import Testing
|
||||||
|
|
||||||
@@ -31,4 +32,65 @@ import Testing
|
|||||||
#expect(shape(isOverText: false, isSelecting: true) == .iBeam)
|
#expect(shape(isOverText: false, isSelecting: true) == .iBeam)
|
||||||
#expect(shape(overlayOpen: true, isEnabled: false, isOverText: false, isSelecting: true) == .iBeam)
|
#expect(shape(overlayOpen: true, isEnabled: false, isOverText: false, isSelecting: true) == .iBeam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func clickable(layer: PointerLayer = .workspace, overlayOpen: Bool = false, isEnabled: Bool = true,
|
||||||
|
isSelecting: Bool = false) -> PointerShape {
|
||||||
|
PointerPolicy.shape(forClickable: layer, overlayOpen: overlayOpen, isEnabled: isEnabled, isSelecting: isSelecting)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func aClickableInAColumnTakesTheHand() {
|
||||||
|
#expect(clickable() == .pointingHand)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func anOpenOverlayGivesTheClickablesBehindItTheArrow() {
|
||||||
|
#expect(clickable(overlayOpen: true) == .arrow)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func aClickableInsideTheOverlayKeepsTheHand() {
|
||||||
|
#expect(clickable(layer: .overlay, overlayOpen: true) == .pointingHand)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func aDisabledClickableKeepsTheArrow() {
|
||||||
|
#expect(clickable(isEnabled: false) == .arrow)
|
||||||
|
#expect(clickable(layer: .overlay, overlayOpen: true, isEnabled: false) == .arrow)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func aDragSelectionKeepsTheIBeamOverAClickable() {
|
||||||
|
#expect(clickable(isSelecting: true) == .iBeam)
|
||||||
|
#expect(clickable(overlayOpen: true, isEnabled: false, isSelecting: true) == .iBeam)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func textAndClickablesShareTheOverlayGate() {
|
||||||
|
#expect(PointerPolicy.isBehindOverlay(.workspace, overlayOpen: true))
|
||||||
|
#expect(!PointerPolicy.isBehindOverlay(.workspace, overlayOpen: false))
|
||||||
|
#expect(!PointerPolicy.isBehindOverlay(.overlay, overlayOpen: true))
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor @Test func aRegionOutOfViewHasAnEmptyFiniteAreaAndNoCursorRect() {
|
||||||
|
let area = OffscreenRegion(frame: NSRect(x: 0, y: 0, width: 210, height: 24)).visibleRectWithoutScrollers
|
||||||
|
#expect(area.isEmpty)
|
||||||
|
#expect(area.origin.x.isFinite && area.origin.y.isFinite)
|
||||||
|
#expect(!area.isUsableCursorRect)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test func removingAStripFromANullRectStaysFinite() {
|
||||||
|
let rest = NSRect.null.removing(NSRect(x: 0, y: 0, width: 10, height: 10))
|
||||||
|
#expect(rest.origin.x.isFinite && rest.origin.y.isFinite)
|
||||||
|
#expect(!NSRect.null.isUsableCursorRect)
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainActor @Test func aRegionsAreaNeverExceedsItsBounds() {
|
||||||
|
let region = UnclippedRegion(frame: NSRect(x: 0, y: 0, width: 49, height: 27))
|
||||||
|
#expect(region.visibleRectWithoutScrollers == region.bounds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stands in for a view in SwiftUI's platform-view host, which does not clip its visible rect.
|
||||||
|
private final class UnclippedRegion: PointerRegionView {
|
||||||
|
override var visibleRect: NSRect { NSRect(x: -629, y: -904.5, width: 1512, height: 940) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A region scrolled out of view: its visible rect misses its bounds.
|
||||||
|
private final class OffscreenRegion: PointerRegionView {
|
||||||
|
override var visibleRect: NSRect { NSRect(x: 500, y: 500, width: 10, height: 10) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,3 +104,4 @@ How the suites are organised and how to run one: see the Testing section of the
|
|||||||
- **Config.** `files.followGitignore` defaults to **false** (the main-process value). There is no CSS layer: code font and size come from config/Typography.
|
- **Config.** `files.followGitignore` defaults to **false** (the main-process value). There is no CSS layer: code font and size come from config/Typography.
|
||||||
- **One file, no Original.** The editor deliberately has no tabs and no Original mode. `git.defaultDiffMode: "original"` in an older config decodes as `"updated"`.
|
- **One file, no Original.** The editor deliberately has no tabs and no Original mode. `git.defaultDiffMode: "original"` in an older config decodes as `"updated"`.
|
||||||
- **SwiftTerm** has no line-height or letter-spacing setting, so `terminal.lineHeight`/`letterSpacing` from the config are ignored.
|
- **SwiftTerm** has no line-height or letter-spacing setting, so `terminal.lineHeight`/`letterSpacing` from the config are ignored.
|
||||||
|
- **Pointer.** `Components/PointerPolicy.swift` is the one rule: I-beam, pointing hand or arrow. Text views conform to `PointerTextTarget`; a SwiftUI button or row gets the hand with `.pointerHand()` on the exact view a left click acts on, never on a container. Its region view takes no clicks and reads `\.isEnabled`, `disabledLook` and `\.pointerLayer` (`.overlay` under `OverlayHost` and the ⇧⌘O list), so a disabled button and every column behind an overlay keep the arrow. `updateCursor` asks the `PointerOwner` under the mouse first, so a text field inside a clickable row keeps the I-beam. AppKit hands a cursor update to the hit view, and a region view takes no hits, so `NSHostingView` would set the arrow; `PointerPolicy.installCursorUpdateMonitor()` (called at launch) swallows every cursor update in the key window, passes every mouse move on untouched, and for both runs `updateCursor` once afterwards (`scheduleUpdate`, coalesced per window). Inside an event SwiftUI's hit test returns its root view, so nothing calls `updateCursor` from inside an event, and the deferred call never resets cursor rects, which would fire new updates. Region views and the terminals keep a `PointerTracker` area (cursor update, enter, exit) so AppKit still sends an update when the mouse crosses their edge.
|
||||||
|
|||||||
@@ -214,6 +214,16 @@ Inside the overlay:
|
|||||||
- When nothing matches, each column shows a brief no-results message.
|
- When nothing matches, each column shows a brief no-results message.
|
||||||
- `Esc` closes the overlay. The respected excludes are the same as the Explorer (`files.exclude` and, when on, gitignore).
|
- `Esc` closes the overlay. The respected excludes are the same as the Explorer (`files.exclude` and, when on, gitignore).
|
||||||
|
|
||||||
|
### Mouse pointer
|
||||||
|
|
||||||
|
The pointer shows what a left click does at that spot. It depends only on what lies under the mouse.
|
||||||
|
|
||||||
|
- **Pointing hand** only where a left click runs an action: buttons (title-bar toggles and tools, `?`, Preview, Diff, Commit, Push, stage `+` / unstage `−`, Stage all / Unstage all, dialog buttons, Collapse, search chips), clickable rows (Git file rows, Explorer rows, search results, recent files and projects, launcher rows, symbol popup rows, context-menu items) and the project name in the title bar. Never on a view that only reacts to a right-click, a tooltip or hover.
|
||||||
|
- **I-beam** where a click places a caret or starts a selection: the code (also below the last line), the Markdown preview, both terminals, the commit message and every overlay input.
|
||||||
|
- **Arrow** everywhere else: labels, headers, folder labels, the gutter, the status bar, scrims, toasts, empty states, and a disabled button such as Commit with nothing staged.
|
||||||
|
- With an overlay open, every column behind it shows the arrow; the overlay's own buttons, rows and inputs keep theirs.
|
||||||
|
- A splitter shows a resize arrow; `Cmd` over a known PHP class name in the code shows the hand. No other pointers are used.
|
||||||
|
|
||||||
### Pane resizing
|
### Pane resizing
|
||||||
|
|
||||||
Dragging any splitter resizes the adjacent panes. Positions persist across launches.
|
Dragging any splitter resizes the adjacent panes. Positions persist across launches.
|
||||||
|
|||||||
@@ -87,6 +87,11 @@ A Helder window holds one project. It has a title bar on top, four columns in th
|
|||||||
- In the Git and Explorer columns, `Up` and `Down` move the row cursor and `Return` opens the row. See [Git](git.md) and [Explorer](explorer.md).
|
- In the Git and Explorer columns, `Up` and `Down` move the row cursor and `Return` opens the row. See [Git](git.md) and [Explorer](explorer.md).
|
||||||
- Clicking a row in Git or Explorer takes the keyboard out of a text field in another column.
|
- Clicking a row in Git or Explorer takes the keyboard out of a text field in another column.
|
||||||
|
|
||||||
|
### The mouse pointer
|
||||||
|
- A pointing hand means a left click runs an action: a button, a clickable row, the project name.
|
||||||
|
- An I-beam means a click places the cursor or selects text: the code, the Markdown preview, the terminals and every input.
|
||||||
|
- Everywhere else the pointer is an arrow, also over a disabled button and over the columns behind an open dialog or search.
|
||||||
|
|
||||||
### Refresh (`Cmd+R`)
|
### Refresh (`Cmd+R`)
|
||||||
- Re-reads git, the file tree and the open file from disk. The disk wins over unsaved edits in the open file.
|
- Re-reads git, the file tree and the open file from disk. The disk wins over unsaved edits in the open file.
|
||||||
- Every column flashes lighter for a moment, so you can see the refresh happened even when nothing changed.
|
- Every column flashes lighter for a moment, so you can see the refresh happened even when nothing changed.
|
||||||
|
|||||||
Reference in New Issue
Block a user