Every extension

search

Behaviour takes options 1.37 kB gzipped

Find and replace.

Every match is a decoration, so nothing about searching touches the document, and replacing all of them is one transaction and one undo step.

Matches are recomputed per block and cached on the block node: typing in one paragraph rescans that paragraph and reads every other paragraph's matches back, so a search left open while writing costs the paragraph being written, not the document.


            editor.commands.setSearch({ query: 'colour', caseSensitive: false })
editor.commands.nextMatch()
editor.commands.replaceMatch('color')
editor.commands.replaceAllMatches('color')
editor.commands.clearSearch()
          

Adding it

import { createEditor, document, paragraph, text, search } from '@matrajs/core'

const editor = createEditor({
  extensions: [document, paragraph, text, search({ … })],
  element: document.querySelector('#editor'),
})

There is no separate package · search is already in @matrajs/core, and an extension you do not import is not in your bundle. document, paragraph and text are the floor every document needs.

Options

Field Type
name string Extension name, and the key `editor.extensionState` reads.
matchClass string Class on every match.
currentClass string Class on the current match, in addition to `matchClass`.

Commands

Styles

This one needs a stylesheet to look right, and ships the minimum as a string rather than a file · nothing is loaded unless you load it.


          import { searchCSS } from '@matrajs/core'

const style = document.createElement('style')
style.textContent = searchCSS
document.head.append(style)
        

← All 81 extensions

Edit this page on GitHub