queryfield

package
v1.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func (f *Field) Active() bool

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) Blur

func (f *Field) Blur()

Blur releases focus without discarding the query.

func (*Field) Clear

func (f *Field) Clear()

Clear empties the query and leaves focus where it is.

func (*Field) Cursor

func (f *Field) Cursor() int

Cursor is the caret's rune offset into the query.

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) Focused

func (f *Field) Focused() bool

Focused reports whether the field owns the keyboard.

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

func (f *Field) HandlePaste(msg tea.PasteMsg) KeyResult

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

func (f *Field) Insert(text string)

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) Query

func (f *Field) Query() string

Query is the text.

func (*Field) Render

func (f *Field) Render(width int, placeholder, right string) (string, Rects)

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.

func (*Field) Reset

func (f *Field) Reset()

Reset clears both query and focus — used when the underlying list is replaced wholesale (a project switch, a plugin reinit).

func (*Field) SetQuery

func (f *Field) SetQuery(query string)

SetQuery replaces the text and puts the caret at its end, which is where a restored or programmatically set query leaves it.

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

type Rects struct {
	Right mouse.Rect
	Clear mouse.Rect
}

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".

func RenderRow

func RenderRow(width int, row Row) (string, Rects)

RenderRow draws the app's query bar: the `/` prompt and the text in styles.Muted while idle and styles.Title while taking text, a ▌ block caret at the cursor on the focused row, the right cell pinned to the far edge, and the × clear control right of that.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL