163487b5e3
Add Calibre-parity search modes to the reader's full-text search. The "Match Whole Words" toggle becomes a single-select mode group: Contains, Whole Words, Regular Expression, Nearby Words. - Regex and nearby-words matching live in the foliate-js submodule (bumped here); the sidebar threads `mode` and `nearbyWords` through. - Nearby distance is chosen with a "within N words" control (5/10/20/50, default 10), not parsed from the query, so trailing numbers stay literal search words. - Per-mode modifiers: Match Diacritics is greyed out for regex (no-op). - Calm inline error for invalid regex / too-few nearby words, a no-results state, and a results-count footer. - Nearby matches render a segmented excerpt emphasizing each matched word and highlight every word in the book. - BookConfig schema v2 -> v3 migrates the deprecated `matchWholeWords` boolean to `mode` (still written for sync back-compat). Also fix two search interactions: - option changes (e.g. within-N-words) now take effect immediately by reading the latest config at search time instead of a stale closure. - closing search from the results nav bar now exits the sidebar search mode, not just the results (search-bar visibility lifted to the store). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
11 lines
503 B
TypeScript
11 lines
503 B
TypeScript
import { BookSearchConfig, SearchMode } from '@/types/book';
|
|
|
|
export const DEFAULT_NEARBY_WORDS = 10;
|
|
|
|
export const modeToWholeWords = (mode: SearchMode): boolean => mode === 'whole-words';
|
|
|
|
// v2 configs (and pre-v3 sync peers) encode whole-word matching as a boolean and
|
|
// have no `mode`. Derive the mode from the boolean when `mode` is absent.
|
|
export const ensureSearchMode = (config: Partial<BookSearchConfig>): SearchMode =>
|
|
config.mode ?? (config.matchWholeWords ? 'whole-words' : 'contains');
|