prism-react-editor
Version:
Lightweight, extensible code editor component for React apps
35 lines (33 loc) • 1.87 kB
TypeScript
import { PrismEditor } from '../../types';
import { SearchFilter } from './search';
/**
* Hook that highlights selection matches in an editor.
* @param caseSensitive Whether or not matches must have the same case. Defaults to false.
* @param minLength Minimum length needed to perform a search. Defaults to 1.
* @param maxLength Maximum length at which to perform a search. Defaults to 200.
* Lower values of `minLength` and higher values of `maxLength` can impact performance.
*
* The CSS-selector `.selection-matches span` can be used to style the matches.
*/
export declare const useHighlightSelectionMatches: (editor: PrismEditor, caseSensitive?: boolean, minLength?: number, maxLength?: number) => void;
/**
* Hook that highlights all instances of the word the cursor is on if there's no selection.
* @param filter Function that can filter away matches based on their position.
* @param includeHyphens A function returning whether or not hyphens should be included in the search.
* For languages that don't commonly use hyphens as an operator (such as CSS), it makes sense to
* return true. If this parameter is omitted, hyphens are not included.
*
* The CSS-selector `.word-matches span` can be used to style the matches.
*
* @example
* This filters away all words that start inside a string, comment or keyword or regex token.
* Different filter functions should be chosen based on the language.
* ```
* const selector = ".string, .comment, .keyword, .regex"
* const filter = start => !getClosestToken(editor, selector, 0, 0, start)
* const includeHyphens = position => getLanguage(editor, position) == "css"
*
* useHighlightCurrentWord(editor, filter, includeHyphens)
* ```
*/
export declare const useHighlightCurrentWord: (editor: PrismEditor, filter?: SearchFilter, includeHyphens?: (cursorPosition: number) => boolean) => void;