Find & replace

Search, highlight matches, replace one or all.

Try this feature →

Import

typescript
import { findReplacePlugin } from 'halka/plugins/find-replace';

Usage

  • Open with Mod+F or Mod+H, or call findReplace.open
  • Next/Previous navigate matches; highlight stays visible while find input has focus
  • Case sensitive and whole word options via findReplace.setOptions
  • Replace and Replace all update document and refresh matches

Commands

CommandDescription
findReplace.open / closeOpen or close panel
findReplace.setOptionsSet query, replacement, options
findReplace.find / findNext / findPreviousNavigate matches
findReplace.replace / replaceAllReplace matches

State

Read plugin state with editor.getState(name). Listen to formatChange to refresh UI when the selection moves.

StateDescription
findReplace.stateQuery, match count, current index
typescript
const findState = editor.getState('findReplace.state') as {
  isOpen: boolean;
  query: string;
  replacement: string;
  caseSensitive: boolean;
  wholeWord: boolean;
  matchCount: number;
  currentIndex: number;
  currentMatch: { start: number; end: number } | null;
};

// Drive a find/replace panel from state
if (findState.isOpen) {
  console.log(`Match ${findState.currentIndex + 1} of ${findState.matchCount}`);
}

editor.on('formatChange', () => {
  const state = editor.getState('findReplace.state');
});

Shortcuts

ShortcutAction
Mod+FOpen find
Mod+HOpen find & replace

Example

typescript
editor.execCommand('findReplace.open', { query: 'editor' });
editor.execCommand('findReplace.findNext');
editor.execCommand('findReplace.replaceAll');

Notes

Uses CSS Highlight API for match highlighting while find input has focus.

MIT · Halka Editor