CommandPalette
搜索并执行应用命令。
实时预览
正在加载预览…
参数配置
全部字段 12
CommandPaletteOptions
Styles · 0
CommandActionItems
列表项 · 3
CommandAction
列表项 · 0
CommandAction
列表项 · 0
CommandAction
列表项 · 0
Go 代码
Go
// Inside a view; c is *ui.Context, t is nui.Theme.
// Keep s (example state) outside the view. See the complete example.
nui.Button(c.Key("open"), t, "Open commands", nui.ButtonOptions{}).OnClick(func() { s.Commands.Open = true })
nui.CommandPalette(c.Key("commands"), t, &s.Commands, nui.CommandPaletteOptions{Title: "Command palette", Placeholder: "Search commands…", DisableShortcut: true, OnSelect: func(id string) { s.Selected = id }})
ui.Text(c, s.Selected)使用说明
点击 Open commands 搜索示例命令并执行,所选命令 ID 显示在下方。此预览关闭全局快捷键以避免占用浏览器按键;搜索索引只初始化一次,实例释放时关闭状态。
API 参考
CommandPalette
源码func CommandPalette(c *ui.Context, t Theme, s *CommandPaletteState, o CommandPaletteOptions) ui.ElementCommandPaletteOptions
源码type CommandPaletteOptions struct {
Title, Placeholder string
Limit int
ShortcutKey ui.Key
ShortcutMods ui.Modifiers
DisableShortcut bool
// Search starts application work; publish Results.Complete on the UI thread.
// Nil uses the immutable index on a worker and a bounded mailbox.
Search func(context.Context, QueryTicket, string, string)
OnSelect func(string)
Modal ModalOptions
Decoration
}| 字段 | 类型 | 说明 |
|---|---|---|
Title | stringGo 零值: | 标题文字。 |
Placeholder | stringGo 零值: | 没有输入或选择时的占位文字。 |
Limit | intGo 零值: | 结果数量或同时显示的项目上限。 |
ShortcutKey | ui.KeyGo 零值: | 快捷键主键。 |
ShortcutMods | ui.ModifiersGo 零值: | 快捷键修饰键。 |
DisableShortcut | boolGo 零值: | 禁用组件默认快捷键。 |
Search | func(context.Context, QueryTicket, string, string)Go 零值: | 应用提供的异步搜索入口。 |
OnSelect | func(string)Go 零值: | 激活或选择项目时通知应用的回调。 |
Modal | ModalOptionsGo 零值: | 内嵌对话框的配置。 |
UI | StylesGo 零值: | 以部件名称为键覆盖外观和间距。 |
Style | func(Slot, ui.Element)Go 零值: | 同步配置当前构建的部件;不要保留 Element。 |