Documentation
¶
Overview ¶
Package command builds a searchable command palette on ui's public API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Palette ¶
Palette shows a modal palette while s.Open is true. Typing searches titles and keywords by case-insensitive subsequences, with exact/prefix and word-boundary matches ranked first; whitespace separates search terms. Up/Down and Page Up/Down move past disabled results, Enter chooses, and Escape or a click outside closes. Only visible result rows are built. The input keeps focus, with the chosen option its active descendant.
The ID returned by a choice is reported once, and the palette closes before it is returned. Dispatch it after Palette; actions belong to the app. Invalid (empty or duplicate) IDs panic when items change.
Types ¶
type Item ¶
Item is an app command. ID must be nonempty and unique in a palette; Title is its name, Detail optional secondary text, and Keywords search aliases. Shortcut is the key that runs the item, drawn as a menu draws one: the app owns the binding itself. A disabled item remains visible but cannot be chosen.
type Shortcut ¶
Shortcut is a key with modifiers, drawn as a menu draws one: Cmd and K read "⌘K" on a Mac and "Ctrl+K" elsewhere. The zero value draws nothing.
type State ¶
type State struct {
Open bool
Query string
// Label names the dialog and input; Placeholder and EmptyText override
// their text. Empty strings use MyGo's localized Search and No results.
Label, Placeholder, EmptyText string
// Width and Height are DIPs: 560 and 320 by default, capped by the
// window. Height is the results list's height, not the whole dialog.
Width, Height float32
// contains filtered or unexported fields
}
State is a palette's state, kept by the app for one view in one window. Set Open to show it, and call Palette every frame, including while closed. Closing clears Query, so an app can fill one in before opening the palette. Items can change while it is open; the keyboard choice follows its ID unless the query changes or the item disappears. As with other UI state, use it on the UI thread.