Documentation
¶
Overview ¶
Package queryfield is the app's one inline query bar: its state, its keys, and its look.
Every `/` bar in sidecar used to be hand-rolled from append and backspace, so the caret could not move, a word could not be deleted, and a paste arrived character by character or not at all. This package answers that once by wrapping a bubbles textinput.Model — which brings cursor movement, word forward and back, word delete, home and end, and paste with no code of its own — behind the row RenderRow draws.
It lives outside internal/workspacelist because the surfaces that need it have nothing to do with workspaces: the plugin browser, the file browser, the git history, the notes search, Sessions and the terminal all want the same field, and none of them should import a workspace list to get a text box. workspacelist.Filter is now a thin wrapper over the type here.
Index ¶
- Constants
- type Field
- func (f *Field) Active() bool
- func (f *Field) Blur()
- func (f *Field) Clear()
- func (f *Field) Cursor() int
- func (f *Field) Focus()
- func (f *Field) Focused() bool
- func (f *Field) HandleKey(msg tea.KeyPressMsg) KeyResult
- func (f *Field) HandlePaste(msg tea.PasteMsg) KeyResult
- func (f *Field) Insert(text string)
- func (f *Field) Query() string
- func (f *Field) Render(width int, placeholder, right string) (string, Rects)
- func (f *Field) Reset()
- func (f *Field) SetQuery(query string)
- type KeyResult
- type Rects
- type Row
Constants ¶
const ClearGlyph = "×"
ClearGlyph is the row's clear control. It is drawn only when there is something to clear, and it is a hit target wherever it is drawn.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is one query bar: the text, the caret, and whether the row owns the keyboard. It is a plain value with a usable zero — query state is in-memory per consumer and is never written to config or project state, and a surface that holds one as a struct field must not have to remember a constructor.
func New ¶
func New() Field
New builds a field. The zero value works too; this exists for a caller that would rather say so.
func (*Field) Active ¶
Active reports that the field still affects the list. A query survives losing focus so a user can filter, press enter, and keep working inside the narrowed list.
func (*Field) Focus ¶
func (f *Field) Focus()
Focus enters editing. `/` is the explicit entry precisely so printable commands keep working when the field is not focused.
func (*Field) HandleKey ¶
func (f *Field) HandleKey(msg tea.KeyPressMsg) KeyResult
HandleKey applies one key while the field has focus. It returns KeyIgnored for anything the list beneath should handle itself.
func (*Field) HandlePaste ¶
HandlePaste puts a bracketed paste into the query. Newlines and tabs are collapsed by the input's own sanitizer, because a query bar is one line.
func (*Field) Insert ¶
Insert puts text in at the caret. Typed keys and pasted text go through the same path, so a pasted branch name filters exactly like a typed one.
func (*Field) Render ¶
Render draws this field's row, with the caller's right-hand cell and the × wherever there is a query to clear. It is the call a surface makes; RenderRow is for a surface whose query state is not a Field.
type KeyResult ¶
type KeyResult uint8
KeyResult tells a consumer what a key did to the field, so the list beneath keeps its own navigation while the field owns the text.
const ( // KeyIgnored: the field did not want this key. Navigation keys land here on // purpose — arrows, paging and ctrl+n/ctrl+p must stay live while a query // is being typed. KeyIgnored KeyResult = iota // KeyHandled: the query or the caret moved (or a first escape cleared it). KeyHandled // KeyAccept: enter — leave the focused item selected, return to the list. KeyAccept // KeyExit: escape on an empty query — field focus is released. KeyExit )
type Rects ¶
Rects is where a rendered row's two right-hand cells landed, in the row's own coordinates, so a host can register them.
Each is the zero rect when its cell was not drawn — nothing to clear, no right cell, or a row too narrow to hold one — and a host that registers the zero rect registers nothing. That is the rule the whole row follows: a region for a control that is not there is a hole in the query bar, where a click is otherwise "focus the query".
type Row ¶
type Row struct {
Query string
Cursor int
Focused bool
// Placeholder replaces the query while it is empty and the row is idle.
Placeholder string
// Right is a rendered cell pinned to the right edge: a count, an outcome,
// or nothing. It is already styled, because only the caller knows what the
// number it is reporting means.
Right string
// Clearable draws the × control right of everything else. A caller sets it
// when there is something to clear AND it will register the rect RenderRow
// hands back: a control nothing listens to is worse than no control.
Clearable bool
}
Row is one query bar's whole content: what has been typed, where the caret is, whether the row is taking text, the placeholder to show when it is not, and an already-styled right-aligned cell.
It exists because the app has more than one query bar and only one look for them. A surface whose query lives somewhere else — the plugin browser's per-collection state, say — renders through RenderRow directly rather than imitating it.