Focus Ring 焦点环 macos

Enabled

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

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 First responder第一响应者 NSWindow.firstResponder

    “The control that will get my typing” is the window's first responder.

    “我打字会送到的那个控件”就是窗口的第一响应者。

    Prompt fragmentPrompt 片段

    the NSWindow.firstResponder control that currently receives keyboard input

    当前接收键盘输入的 NSWindow.firstResponder 控件

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

Preserve the native Focus Ring around the first responder. In AppKit, make the control eligible for first-responder status, move focus with NSWindow.makeFirstResponder(_:), and keep NSView.focusRingType at .default; in SwiftUI, use View.focusable(_:) with FocusState. Leave enough space for the standard macOS accent-colored ring and do not replace it with a custom border.

保留第一响应者周围的原生焦点环。在 AppKit 中,让控件有资格成为第一响应者,用 NSWindow.makeFirstResponder(_:) 移动焦点,并保持 NSView.focusRingType 为 .default;在 SwiftUI 中,使用 View.focusable(_:) 配合 FocusState。为标准的 macOS 强调色焦点环留出足够空间,不要用自定义边框替代它。

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

Debug my macOS focus ring (NSView.focusRingType, SwiftUI .focusable/.focusEffectDisabled). Rule out: Full Keyboard Access (AppleKeyboardUIMode) on the user's Mac making every first control grab focus and show a ring; focusRingType = .none silenced by a custom drawFocusRingMask; the ring clipped by an ancestor that clips to bounds; SwiftUI focus state fighting an explicit makeFirstResponder call. The symptom:

调试我的 macOS 焦点环(NSView.focusRingType、SwiftUI .focusable/.focusEffectDisabled)。逐一排除:用户 Mac 上的全键盘控制(AppleKeyboardUIMode)让每个首个控件都抢占焦点并显示焦点环;自定义 drawFocusRingMask 配合 focusRingType = .none 把焦点环屏蔽了;焦点环被裁切到边界的祖先视图裁掉;SwiftUI 的焦点状态与显式调用 makeFirstResponder 互相打架。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSView.focusRingType
AppKit NSWindow.makeFirstResponder(_:)
AppKit NSFocusRingType
SwiftUI View.focusable(_:)
SwiftUI FocusState

See also相关词条