@eigenpal/docx-editor-core/utils/findReplace
Find & Replace Utility Functions
Pure utility functions for text search, pattern matching, and document search. Lifted from packages/react/src/components/dialogs/ findReplaceUtils.ts so the React adapter and the Vue adapter share one implementation.
Functions(12)
createDefaultFindOptions
Create default find options
declare function createDefaultFindOptions(): FindOptions;createSearchPattern
Create a regex pattern from search text and options
declare function createSearchPattern(searchText: string, options: FindOptions): RegExp | null;escapeRegexString
Escape string for use in regex pattern
declare function escapeRegexString(str: string): string;findAllMatches
Find all matches of search text in content
declare function findAllMatches(content: string, searchText: string, options: FindOptions): Array<{
start: number;
end: number;
}>;findInDocument
Find all matches in a document
declare function findInDocument(document: any, searchText: string, options: FindOptions): FindMatch[];findInParagraph
Find matches in a single paragraph
declare function findInParagraph(paragraph: any, searchText: string, options: FindOptions, paragraphIndex: number): FindMatch[];getDefaultHighlightOptions
Get default highlight options
declare function getDefaultHighlightOptions(): HighlightOptions;getMatchCountText
Get match count for status display
declare function getMatchCountText(result: FindResult | null): string;isEmptySearch
Check if search text is empty or whitespace-only
declare function isEmptySearch(searchText: string): boolean;replaceAllInContent
Replace text in content
declare function replaceAllInContent(content: string, searchText: string, replaceText: string, options: FindOptions): string;replaceFirstInContent
Replace first match in content
declare function replaceFirstInContent(content: string, searchText: string, replaceText: string, options: FindOptions, startIndex?: number): {
content: string;
replaced: boolean;
matchStart: number;
matchEnd: number;
};scrollToMatch
Scroll to a match in the document
declare function scrollToMatch(containerElement: HTMLElement | null, match: FindMatch): void;Interfaces(4)
FindMatch
A single match result in the document
interface FindMatch| Member | Type | Summary |
|---|---|---|
| contentIndex | number | Index of the run/content within the paragraph |
| endOffset | number | Character offset for end of match |
| paragraphIndex | number | Index of the paragraph containing the match |
| startOffset | number | Character offset within the content |
| text | string | The matched text |
FindOptions
Find options for controlling search behavior
interface FindOptions| Member | Type | Summary |
|---|---|---|
| matchCase | boolean | Whether to match case |
| matchWholeWord | boolean | Whether to match whole words only |
| useRegex? | boolean | Whether to use regular expressions (future) |
FindResult
Find result with all matches
interface FindResult| Member | Type | Summary |
|---|---|---|
| currentIndex | number | Current match index (0-based) |
| matches | FindMatch[] | All matches found |
| totalCount | number | Total match count |
HighlightOptions
Highlight options for document rendering
interface HighlightOptions| Member | Type | Summary |
|---|---|---|
| currentMatchColor | string | Background color for current match |
| otherMatchColor | string | Background color for other matches |