CommandPalette

搜索并执行应用命令。

实时预览

正在加载预览…

参数配置

全部字段 12

CommandPaletteOptions

ModalOptions
Styles · 0
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.Element

CommandPaletteOptions

源码
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
}
字段类型说明
Titlestring

Go 零值: ""

标题文字。

Placeholderstring

Go 零值: ""

没有输入或选择时的占位文字。

Limitint

Go 零值: 0

结果数量或同时显示的项目上限。

ShortcutKeyui.Key

Go 零值: zero value

快捷键主键。

ShortcutModsui.Modifiers

Go 零值: zero value

快捷键修饰键。

DisableShortcutbool

Go 零值: false

禁用组件默认快捷键。

Searchfunc(context.Context, QueryTicket, string, string)

Go 零值: nil

应用提供的异步搜索入口。

OnSelectfunc(string)

Go 零值: nil

激活或选择项目时通知应用的回调。

ModalModalOptions

Go 零值: zero value

内嵌对话框的配置。

UIStyles

Go 零值: zero value

以部件名称为键覆盖外观和间距。

Stylefunc(Slot, ui.Element)

Go 零值: nil

同步配置当前构建的部件;不要保留 Element。