Concepts

Editor

6min

All of the behaviors, content and state of a Slate editor is rolled up into a single, top-level Editor object. It has an interface of:

TypeScript


It is slightly more complex than the others, because it contains all of the top-level functions that define your custom, domain-specific behaviors.

The children property contains the document tree of nodes that make up the editor's content.

The selection property contains the user's current selection, if any.

The operations property contains all of the operations that have been applied since the last "change" was flushed. (Since Slate batches operations up into ticks of the event loop.)

The marks property stores formatting to be applied when the editor inserts text. If marks is null, the formatting will be taken from the current selection.

Overriding Behaviors

In previous guides we've already hinted at this, but you can override any of the behaviors of an editor by overriding its function properties.

For example, if you want to define link elements that are inline nodes:

JS


Or maybe you want to override the insertText behavior to "linkify" URLs:

JS


Or you can even define custom "normalizations" that take place to ensure that links obey certain constraints:

JS


Whenever you override behaviors, be sure to call the existing functions as a fallback mechanism for the default behavior. Unless you really do want to completely remove the default behaviors (which is rarely a good idea).

🤖 For more info, check out the Editor Instance Methods to Override API Reference

Helper Functions

The Editor interface, like all Slate interfaces, exposes helper functions that are useful when implementing certain behaviors. There are many, many editor-related helpers. For example:

JS


There are also many iterator-based helpers, for example:

JS


🤖 For more info, check out the Editor Static Methods API Reference



Updated 08 May 2024
Doc contributor
Did this page help you?