Skip to content

FindReplace ​

A find and replace bar over the matcher of an editor.

tsx
import { FindReplace } from '@adecore/editor-react';
import { EditorFrame } from '../shared/editor-frame.tsx';
import { SAMPLE, useEditor } from '../shared/editor.ts';

const OPTIONS = { text: SAMPLE, language: 'typescript', theme: 'demo' } as const;

export default function FindReplaceDemo() {
    const { host, editor } = useEditor(OPTIONS);

    return <EditorFrame host={host} toolbar={editor === null ? undefined : <FindReplace editor={editor} className="w-full" />} />;
}
tsx
<FindReplace editor={editor} onClose={() => setFindOpen(false)} />
PropTypeMeaning
editorEditorThe editor to search
onClose() => voidEscape in the bar; the bar does not hide itself
classNamestringOn the bar

The bar has case, whole word and regular expression toggles, search in selection, a match count, previous and next, and a replace row with preserve case, replace and replace all. Enter goes to the next match, Shift+Enter to the previous. An invalid regular expression shows an error. Past the editor's mark limit the count ends with + (1 / 10,000+); replace all still covers every match. Unmounting the bar ends the find.

The app decides when the bar shows and which key opens it; the findNext, findPrevious and replace ids of the key table name keys for that.

Licenses and third-party notices are listed in each package.