findbar

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package findbar is find and replace: a bar on the context line rather than a dialog, in the spirit of less and vim. Matches highlight in the grid as you type and the active cell follows the current one. Options are toggles shown as chips and switched with Alt keys, as in VS Code's find widget. The scope chip says where to search, as Sheets' "Search" choice: this sheet, all sheets, or the range selected when the bar opened; Alt+S goes through them. It knows the UI only through Host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {

	// Vim makes Enter close the bar on the match, as / does in vim.
	Vim bool
	// contains filtered or unexported fields
}

Bar is the find bar: the search, its options and its matches. It outlives being open, so the last search can be reopened or repeated.

func New

func New(h Host) *Bar

New returns a bar with no search yet.

func (*Bar) Again

func (f *Bar) Again(d int)

Again goes to the next (d = 1) or previous (d = -1) match of the last search from the active cell, without opening the bar, as n and N do in vim and less, and says where it went. It does nothing without a search to repeat (see Searched).

func (*Bar) Changed

func (f *Bar) Changed()

Changed re-runs the search as the query is typed.

func (*Bar) ContextLine

func (f *Bar) ContextLine() (left, right string)

ContextLine renders the bar for the context line, with the match count on the right.

func (*Bar) Cursor

func (f *Bar) Cursor() (x, y int)

Cursor puts the terminal cursor in the focused field, whose text ends its part.

func (*Bar) Field

func (f *Bar) Field() int

func (*Bar) Found

func (f *Bar) Found(s *sheet.Sheet, a sheet.Addr) bool

Found reports whether a on s is a match.

func (*Bar) Indicator

func (f *Bar) Indicator() string

func (*Bar) Key

func (f *Bar) Key(k tea.KeyPressMsg) tea.Cmd

func (*Bar) Layout

func (f *Bar) Layout() []overlay.Box

Layout is empty: the bar is drawn on the context line.

func (*Bar) Matches

func (f *Bar) Matches() []Match

Matches are the matches of the search, in order.

func (*Bar) Mouse

func (f *Bar) Mouse(e overlay.MouseEvent) tea.Cmd

Mouse focuses a field or flips a chip on the bar; a click anywhere else closes the bar and lands where it was clicked.

func (*Bar) Open

func (f *Bar) Open(replace bool)

Open focuses the query, or with replace the replacement once there's a query, and searches.

func (*Bar) Options

func (f *Bar) Options() sheet.FindOptions

Options are the search's options.

func (*Bar) Replacing

func (f *Bar) Replacing() bool

Replacing reports whether the replacement field shows, and Field which field is focused: 0 the query, 1 the replacement.

func (*Bar) Reset

func (f *Bar) Reset(sel *sheet.Rect)

Reset gets the bar ready to open over the sheet shown, keeping the last search. A multi-cell selection sel becomes the search scope, as Sheets' "specific range". The kept query is loaded into the edit line.

func (*Bar) Searched

func (f *Bar) Searched() bool

Searched reports whether there's a search to repeat.

func (*Bar) Status

func (f *Bar) Status() (string, string)

Status shows the keys for moving and replacing, and a reminder of the option keys when there's room. Narrow screens keep the most useful keys.

type Host

type Host interface {
	Theme() *theme.Theme
	Size() (width, height int)
	// Line is the shared edit line the focused field is typed in.
	Line() *lineedit.Line
	Book() *sheet.Workbook
	// Trace is where searches are timed, nested in what is open.
	Trace() *telemetry.Trace
	// At is the sheet shown and its active cell.
	At() (*sheet.Sheet, sheet.Addr)
	// Show shows sheet s with a as the active cell.
	Show(s *sheet.Sheet, a sheet.Addr)
	// Note says how the last action went, on the context line.
	Note(msg string)
	// Edited marks the file modified.
	Edited()
	// Leave closes the bar, keeping its search for Ctrl+F and find next.
	Leave()
	// Press handles a mouse press outside the bar, as on the grid.
	Press(x, y int, button tea.MouseButton) tea.Cmd
}

Host is what the find bar needs of the UI.

type Match

type Match struct {
	Sheet *sheet.Sheet
	At    sheet.Addr
}

Match is a cell on a particular sheet.

Jump to

Keyboard shortcuts

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