Find & replace
Search, highlight matches, replace one or all.
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
| Command | Description |
|---|---|
findReplace.open / close | Open or close panel |
findReplace.setOptions | Set query, replacement, options |
findReplace.find / findNext / findPrevious | Navigate matches |
findReplace.replace / replaceAll | Replace matches |
State
Read plugin state with editor.getState(name). Listen to formatChange to refresh UI when the selection moves.
| State | Description |
|---|---|
findReplace.state | Query, 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
| Shortcut | Action |
|---|---|
Mod+F | Open find |
Mod+H | Open 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.