Pointer (Cursor) 指针(光标) macos

Hover a shape · your pointer becomes it

标本可交互 —— 点点看。Specimen is live — try it.

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Set the macOS pointer with NSCursor — e.g. NSCursor.iBeam.set() — or claim a region with NSView.addCursorRect(_:cursor:) inside resetCursorRects() (SwiftUI: View.pointerStyle(_:), macOS 15+). If the pointer stays stuck as the I-beam after the mouse leaves a text view, the stale cursor rect is the bug: call window.invalidateCursorRects(for: view) so the rects rebuild.

用 NSCursor 设置 macOS 指针 —— 例如 NSCursor.iBeam.set() —— 或在 resetCursorRects() 里用 NSView.addCursorRect(_:cursor:) 认领区域(SwiftUI:View.pointerStyle(_:),macOS 15+)。如果鼠标离开文本视图后指针还卡在 I-beam,那就是过期的 cursor rect 在作怪:调用 window.invalidateCursorRects(for: view) 让 rect 重建。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my macOS pointer/cursor (NSCursor, NSTrackingArea). Rule out: the cursor flickering back to arrow because cursor rects reset on every layout — drive it from cursorUpdate with a tracking area instead; push/pop or hide/unhide calls unbalanced; the spinning beach ball meaning the main thread is blocked, not a cursor bug; a hidden cursor never restored after a drag. The symptom:

调试我的 macOS 指针/光标(NSCursor、NSTrackingArea)。逐项排除:cursor rect 每次布局都重置,指针闪回箭头 —— 改用 tracking area 在 cursorUpdate 里驱动;push/pop 或 hide/unhide 调用不配对;转圈的彩虹海滩球说明主线程卡死,不是指针的 bug;拖拽结束后隐藏的指针没恢复。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSCursor
AppKit NSCursor.iBeam the text-editing pointer文本编辑用的指针
AppKit NSView.addCursorRect(_:cursor:) claim a region; called from resetCursorRects()认领一片区域;在 resetCursorRects() 里调用
SwiftUI View.pointerStyle(_:) macOS 15+macOS 15+
CSS cursor: text the same shapes on the web: pointer, grab, not-allowed…Web 上的同款形状:pointer、grab、not-allowed……

See also相关词条