Extensions

clearFormatting

Behaviour 0.24 kB gzipped

Back to plain text: every mark off the selection, every block a paragraph.

The toolbar button labelled with a crossed-out T. One command rather than a call per mark, so the host does not have to know which marks the editor was built with — and one undo step, because that is what the person pressing it expects to get back.

1 · Install

One package for every extension · there is no @matrajs/clearFormatting to install.

npm i @matrajs/core

2 · Add it to the editor

Import it and put it in the extensions array. That array is the whole feature list: what is not in it is not in your bundle and not in the document's schema.

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

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

3 · Use it

Run a command, and give focus back · a click on a button takes it away.

editor.commands.unsetAllMarks()
editor.focus()

From the keyboard: Mod-\ .

Wired to a button:

const button = document.querySelector('#unsetAllMarks')

button.addEventListener('click', () => {
  editor.commands.unsetAllMarks()
  editor.focus()
})

Commands

Every one returns true if it changed the document and false if it could not · a command that does not apply where the caret is says so rather than throwing.

Command Call
unsetAllMarks editor.commands.unsetAllMarks()
clearBlocks editor.commands.clearBlocks()
clearFormatting editor.commands.clearFormatting()

Keyboard shortcuts

Mod is Command on a Mac and Control everywhere else. To rebind one, put your own extension after this in the array · later keys win.

← All 83 extensions

Edit this page on GitHub