Expand description
Shared text helpers for the note-preview surfaces (the Query panel’s context preview and the note browser’s preview pane). Both highlight query needles in a note’s body and wrap long lines; the case-insensitive matching is the one piece that is both subtle (must stay on character boundaries for every non-ASCII case fold) and was previously implemented twice — once correctly, once dropping highlights for length-changing folds. It lives here now; each surface keeps its own span styling.
Functions§
- match_
ranges - Non-overlapping byte ranges in
haystackwhere any ofneedlesmatches, case-insensitively, earliest- and longest-first. - style_
ranges - Walk
lineagainst precomputed non-overlappingranges(frommatch_ranges, ascending) and emit one item per segment viamk(slice, is_match)— alternating non-match gaps and matched spans, plus the trailing gap. Emptyrangesyields the whole line as a single non-match segment. Shared so the gap/match/tail splitting lives in one place; each caller supplies its own constructor (owned'staticspans vs borrowed'aspans, with its own styles). - wrap_
line - Wrap
lineinto pieces that each fit withinmax_widthcharacters (not bytes). Breaks at word boundaries when possible, hard-breaks an over-long word otherwise. Amax_widthof 0 returns the line unchanged.