fixes cursor

This commit is contained in:
2026-10-05 10:32:09 +02:00
parent 336987d821
commit 201c59c659
12 changed files with 460 additions and 46 deletions
+15 -3
View File
@@ -102,10 +102,11 @@ struct OverlayCommandField: NSViewRepresentable {
}
}
/// The box around an `OverlayCommandField`: an I-beam over all of it, and a click anywhere focuses the field.
final class CommandFieldBox: NSView {
/// The box around an `OverlayCommandField`: a click anywhere in it focuses the field, so all of it takes the I-beam.
final class CommandFieldBox: NSView, PointerTextTarget {
let field: NSTextField
let inset: CGFloat
let pointerLayer = PointerLayer.overlay
init(field: NSTextField, inset: CGFloat) {
self.field = field
@@ -124,8 +125,16 @@ final class CommandFieldBox: NSView {
field.frame = NSRect(x: inset, y: ((bounds.height - height) / 2).rounded(), width: max(0, bounds.width - 2 * inset), height: height)
}
var acceptsPointerText: Bool { field.isEnabled }
func isPointerOverText(atWindowPoint point: NSPoint) -> Bool {
isTopmost(atWindowPoint: point)
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
override func resetCursorRects() {
addCursorRect(bounds, cursor: .iBeam)
addPointerCursorRect(bounds)
}
override func mouseDown(with event: NSEvent) {
@@ -185,6 +194,8 @@ private final class FocusingTextField: NSTextField {
set {}
}
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
guard !focused, window != nil else { return }
@@ -205,6 +216,7 @@ private final class PointerBoundFieldCell: NSTextFieldCell {
private lazy var editor: PointerBoundTextView = {
let editor = PointerBoundTextView()
editor.isFieldEditor = true
editor.pointerLayer = .overlay
return editor
}()