fixes cursor
This commit is contained in:
@@ -57,6 +57,7 @@ private struct NoteEditor: NSViewRepresentable {
|
||||
scroll.hasVerticalScroller = true
|
||||
scroll.autohidesScrollers = true
|
||||
let textView = NoteTextView(frame: .zero)
|
||||
textView.pointerLayer = .overlay
|
||||
textView.isVerticallyResizable = true
|
||||
textView.isHorizontallyResizable = false
|
||||
textView.autoresizingMask = [.width]
|
||||
|
||||
@@ -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
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user