Aa 0.14.1

Find and replace

⌘F in the editor opens a field to find words, every match marked in the text, and a second field to replace them.

Find and replace

Click in the text and press ⌘F. Find colour, replace it with color, then press Replace all.

What it stores

The bar stands at the editor’s top left corner, sixteen squares wide, and takes the focus. Every match is marked in the highlight’s yellow as it is typed, and the bar counts them.

PartWhat it does
The Find fieldWhat to look for. Upper and lower case are found alike.
The Replace fieldWhat a match becomes.
Previous match, Next matchSelect the match before or after, and say which it is: 2 of 5. From the last, Next goes round to the first.
ReplaceReplaces the selected match, or the first when none is selected.
Replace allReplaces every match, one step to undo.
Close findTakes the marks away and gives the editor back its focus.
KeyIn the find bar
EnterNext match.
Shift-EnterPrevious match.
EscapeClose find.

The matches follow the writing: each change in the document while the bar is open finds them again.

Find searches the Markdown the editor stores, not the words as they are drawn, so it also finds what a link’s address or a picture’s name holds. What is replaced is written as Markdown too: **done** in the Replace field makes a bold word. In a read-only editor nothing is replaced.

const matches = editor.find('colour')               // [{ start, end }, …] in the Markdowneditor.find('Colour', true)                         // case matterseditor.decorate(matches.map(({ start, end }) => ({ from: start, to: end, className: 'my-match' })), 'search')editor.replace(matches[0].start, matches[0].end, 'color')

find(query, caseSensitive?) gives the matches as offsets into the Markdown; decorate() marks words on a layer of their own without changing the Markdown, as the find bar does on its find layer. See Decorations and Methods and events.

Undo · Keyboard