Skip to main content

Module find

Module find 

Source
Expand description

Find — the search core.

Search is a literal substring with an ASCII case-fold toggle, or — behind the whole-word / regex options — a line-scoped pattern. (The private Matcher type carries the full rationale for why a line, and not a byte window, is the unit there.) The search bar is app-side chrome; this module owns only the match model, the scan, and what a replacement means.

The one design choice: the match set lives only in the decoration store — the sorted FindMatch decorations ARE the match set, in document order (one fact, one owner). FindState holds the query and the scan bookkeeping, never a shadow list of handles. The set is kept current eagerly: every committed transaction (forward edit, undo, redo — they share the same view-rebase path) runs FindState::on_commit, a windowed repair around each edit, so consumers never see a stale match. The one remaining debounced path is the capped-set refill (FindState::maybe_rescan).

Documented, test-pinned relaxation: for needles that cannot overlap themselves the repaired set is byte-identical to a fresh scan; a self-overlapping needle ("aa") repairs to a maximal valid non-overlapping set whose phase near the edit may differ from the greedy full scan until the next query change.

Structs§

FindQuery
An active find query: the pattern plus its option flags.
FindState
The search view-state: the active query, the active match’s decoration id, and the coverage/cap bookkeeping.

Constants§

FIND_MATCH_CAP
The scan stops after this many matches and records capped — cheap insurance against a pathological query. A capped set is a prefix of the document: everything up to FindState’s coverage frontier is exact, nothing beyond it is represented.

Functions§

default_find_debounce
Debounce window (ms) for the capped-set refill — a user-facing default, exported as a pub fn. This is the ONLY debounced find path: ordinary edits repair the match set eagerly at the commit.
scan
Every non-overlapping match of query in text, leftmost-first, as byte spans; the bool is whether the scan hit FIND_MATCH_CAP.