Every extension

characterCount

Behaviour takes options 0.28 kB gzipped

Live character and word counts, with an optional hard limit.

The limit is enforced by refusing the command rather than truncating: silently cutting a user's paste in half is worse than telling them it did not fit.

Counted only when the document changes. The count used to be taken on every transaction — a caret move, a click, an arrow key — by serialising the whole document to JSON and walking that, so a toolbar showing a word count made every click cost the length of the document.

Adding it

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

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

There is no separate package · characterCount 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
limit number Refuse edits that would take the document past this many characters.

Commands

← All 81 extensions

Edit this page on GitHub