Skip to content

Instantly share code, notes, and snippets.

@lukasb
lukasb / SearchHighlighterPlugin.tsx
Created August 22, 2024 03:42
SearchHighlighterPlugin for lexical
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
import { useEffect, useCallback } from 'react';
// doesn't work in Firefox (but is in Firefox nightly)
// https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API#browser_compatibility
//
// highlights the given search terms in the editor
// then scrolls to the first search term and selects it
export function SearchHighlighterPlugin({