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
@@ -153,6 +153,7 @@ final class CodeEditorController: NSObject, NSTextViewDelegate, NSLayoutManagerD
applyScale(next.fontScale)
textView.isEditable = next.isEditable
textView.isSelectable = true
textView.isPointerActive = next.isShown
var reloaded = false
if document?.id != next.documentID {
+6 -18
View File
@@ -54,9 +54,8 @@ final class CodeTextView: PointerBoundTextView {
override func flagsChanged(with event: NSEvent) {
super.flagsChanged(with: event)
let command = event.modifierFlags.contains(.command)
controller?.commandKeyChanged(command)
if let window { updatePointer(at: window.mouseLocationOutsideOfEventStream, command: command) }
controller?.commandKeyChanged(event.modifierFlags.contains(.command))
if let point = mouseLocation, isTopmost(atWindowPoint: point) { updatePointer(atWindowPoint: point) }
}
override func updateTrackingAreas() {
@@ -67,23 +66,12 @@ final class CodeTextView: PointerBoundTextView {
pointerTracking = area
}
override func mouseMoved(with event: NSEvent) {
super.mouseMoved(with: event)
updatePointer(at: event.locationInWindow, command: event.modifierFlags.contains(.command))
}
override func cursorUpdate(with event: NSEvent) {
super.cursorUpdate(with: event)
updatePointer(at: event.locationInWindow, command: event.modifierFlags.contains(.command))
}
/// The pointing hand over a symbol ⌘-click would follow, the I-beam elsewhere in the text.
private func updatePointer(at windowPoint: NSPoint, command: Bool) {
guard visibleRect.contains(convert(windowPoint, from: nil)) else { return }
if command, controller?.symbol(atWindowPoint: windowPoint) != nil {
/// The pointing hand over a symbol ⌘-click would follow, else the policy's pointer.
override func applyPointer(_ shape: PointerShape, atWindowPoint point: NSPoint) {
if shape == .iBeam, NSEvent.modifierFlags.contains(.command), controller?.symbol(atWindowPoint: point) != nil {
NSCursor.pointingHand.set()
} else {
NSCursor.iBeam.set()
shape.cursor.set()
}
}
@@ -16,6 +16,7 @@ struct MarkdownPreviewView: View {
.padding(EdgeInsets(top: 18, leading: 20, bottom: 48, trailing: 20))
.frame(maxWidth: .infinity, alignment: .leading)
.textSelection(.enabled)
.background(PointerTextRegion())
}
.background(Palette.editor)
.environment(\.openURL, OpenURLAction { url in open(url) })