Documentation
¶
Overview ¶
Package finder is nook's in-file find/replace overlay.
Two modes share state: ModeFind (Ctrl+F) and ModeReplace (Ctrl+H). The overlay renders as a one- or two-line bar at the bottom of the workspace. As the user types, the host re-runs Search and feeds the matches back via WithMatches. Navigation keys jump the cursor between matches; replace edits the buffer one match at a time, replace-all rewrites every line that contains at least one match.
The finder does not own the buffer. The host calls Search to compute matches and ApplyReplacement to produce the rewritten line text; the host applies the edit through editor.Pane.SetLine so the editor's dirty flag, LSP didChange, and version counters stay coherent.
Index ¶
- func ApplyReplacement(line string, m Match, replacement string, re *regexp.Regexp) string
- func CompileRegex(pattern string, caseSensitive bool) (*regexp.Regexp, error)
- type Event
- type Finder
- func (f Finder) CaseSensitive() bool
- func (f Finder) Close() Finder
- func (f Finder) CurrentIndex() int
- func (f Finder) CurrentMatch() (Match, bool)
- func (f Finder) Focus() Focus
- func (f Finder) Height() int
- func (f Finder) IsOpen() bool
- func (f Finder) Matches() []Match
- func (f Finder) Mode() Mode
- func (f Finder) Next() Finder
- func (f Finder) Open(m Mode) Finder
- func (f Finder) Pattern() string
- func (f Finder) PatternErr() error
- func (f Finder) Prev() Finder
- func (f Finder) Replacement() string
- func (f Finder) SelectMatchAt(row, col int) Finder
- func (f Finder) SetPatternErr(err error) Finder
- func (f Finder) SetTheme(t theme.Theme) Finder
- func (f Finder) ToggleCase() Finder
- func (f Finder) ToggleRegex() Finder
- func (f Finder) Update(km tea.KeyMsg) (Finder, Event)
- func (f Finder) UseRegex() bool
- func (f Finder) View() string
- func (f Finder) WithMatches(ms []Match, keepCurrent bool) Finder
- func (f Finder) WithSize(w int) Finder
- type Focus
- type Match
- type Mode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyReplacement ¶
ApplyReplacement returns the new text for the row after substituting the match's range with replacement. The host calls this then writes the result back via editor.Pane.SetLine. If useRegex is true and the pattern compiles, regex expansion (`$1`, `${name}`) is applied to replacement; the caller passes the compiled regex via re so we don't recompile per call.
When re is nil the substitution is a plain byte-range splice.
Types ¶
type Event ¶
type Event int
Event is what the host needs to act on after Update. Most updates produce EventNone; specific keys produce typed events.
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder owns the input fields, toggles, match list, and cursor.
func (Finder) CaseSensitive ¶
CaseSensitive reports whether case-sensitive mode is on.
func (Finder) Close ¶
Close hides the finder. Pattern and replacement are preserved so reopening recalls the last query.
func (Finder) CurrentIndex ¶
CurrentIndex returns the 0-based index of the active match, or -1.
func (Finder) CurrentMatch ¶
CurrentMatch returns the active match, or false if there is none.
func (Finder) Height ¶
Height reports how many rows the finder occupies. 1 for find, 2 for replace mode.
func (Finder) Open ¶
Open shows the finder in the requested mode. If the mode is changed from ModeFind to ModeReplace (or vice versa) the existing pattern is preserved.
func (Finder) PatternErr ¶
PatternErr returns the most recent pattern-compile error (regex mode).
func (Finder) Replacement ¶
Replacement returns the replacement text.
func (Finder) SelectMatchAt ¶
SelectMatchAt picks the first match at-or-after (row, col). Called by the host after a JumpTo so the counter "n/N" stays aligned with the editor's cursor position.
func (Finder) SetPatternErr ¶
SetPatternErr stashes a compile/search error so View can surface it.
func (Finder) SetTheme ¶ added in v0.38.0
SetTheme swaps the palette used for the input box, mode chip, and the `n of N` counter. Next View() picks up the new colors.
func (Finder) ToggleRegex ¶
ToggleRegex flips regex mode and clears the cached pattern-compile error.
func (Finder) Update ¶
Update routes a key event. Returns the new finder and an Event the host should react to (e.g. EventPatternChanged → re-run Search, EventJumpNext → move editor cursor).
func (Finder) WithMatches ¶
WithMatches replaces the match list, computed by the host via Search. If keepCurrent is true the cursor stays on the same row/column as before; if false it resets to the first match. Always clamps to len(matches)-1.
type Match ¶
type Match struct {
Row int // 0-based row
StartCol int // 0-based byte column, inclusive
EndCol int // 0-based byte column, exclusive
}
Match is one hit inside the active buffer.
func Search ¶
Search scans buf and returns every match of pattern. When useRegex is false the pattern is treated as a literal substring (case-folded when caseSensitive is false). When useRegex is true the pattern compiles as Go's RE2; on compile error the returned matches are nil and the error is returned so the caller can stash it via SetPatternErr.
Each line is searched independently; multi-line regex patterns can use `.` to match within a line but cannot cross a newline.