Search Field 搜索栏 macos
A Mac text field with built-in search, clearing, and recent-query controls
Mac 上的文本输入框,自带搜索、清除和最近查询控件
标本可交互 —— 点点看。Specimen is live — try it.
Anatomy — every part, named解剖 —— 每个部件的名字
-
1 Search button搜索按钮
NSSearchFieldCell.searchButtonCellThe magnifying glass inside the leading edge is the search button, not just a decorative placeholder icon.
前缘内侧的放大镜是搜索按钮,不只是装饰性的占位图标。
Prompt fragmentPrompt 片段the search button (NSSearchFieldCell.searchButtonCell): the leading magnifying-glass control inside the NSSearchField
搜索按钮(NSSearchFieldCell.searchButtonCell):NSSearchField 内部前缘的放大镜控件
-
2 Cancel button取消按钮
NSSearchFieldCell.cancelButtonCell“The little x that clears the search” is the field's cancel button.
「清空搜索的小 x」就是这个输入框的取消按钮。
Prompt fragmentPrompt 片段the cancel button (NSSearchFieldCell.cancelButtonCell): the trailing x control that appears for a nonempty query and clears it
取消按钮(NSSearchFieldCell.cancelButtonCell):后缘的 x 控件,有关键词时出现,点击清空
-
3 Recent-searches menu最近搜索菜单
NSSearchFieldCell.searchMenuTemplateThe menu attached to the search icon can list recent queries and a Clear Recents command.
挂在搜索图标上的菜单可以列出最近的查询和一条「清除最近搜索」命令。
Prompt fragmentPrompt 片段the recent-searches menu (NSSearchFieldCell.searchMenuTemplate): a menu from the search button listing saved queries and Clear Recents
最近搜索菜单(NSSearchFieldCell.searchMenuTemplate):从搜索按钮打开的菜单,列出保存过的查询和「清除最近搜索」
Prompt — paste into your agentPrompt —— 直接粘贴给你的代理
Use a native Search Field with NSSearchField (SwiftUI: View.searchable), preserving its leading search button, trailing cancel button when text is present, and optional recent-search menu from NSSearchFieldCell.searchMenuTemplate.
使用原生搜索栏 NSSearchField(SwiftUI:View.searchable),保留前缘的搜索按钮、有文本时出现在后缘的取消按钮,以及来自 NSSearchFieldCell.searchMenuTemplate 的可选最近搜索菜单。
Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时
Debug my macOS search field (NSSearchField). Rule out: search firing only on Return because sendsSearchStringImmediately is false; the clear button clearing text but your code never notified — watch for the empty-string action; the recents menu dead without recentsAutosaveName; the cancel button hidden at small control sizes. The symptom:
调试我的 macOS 搜索栏(NSSearchField)。排除以下可能:sendsSearchStringImmediately 为 false,导致只有按 Return 才触发搜索;清除按钮清掉了文本但你的代码没收到通知——留意空字符串 action;没设 recentsAutosaveName 导致最近搜索菜单失效;控件尺寸太小时取消按钮被隐藏。症状是:
In code代码里叫什么
| Framework框架 | Symbol符号 | Note说明 |
|---|---|---|
| AppKit | NSSearchField | |
| SwiftUI | View.searchable(text:placement:prompt:) | |
| AppKit | NSSearchFieldCell |