Skip to main content
Lumen Editor exposes a built-in event system that lets you react to content changes, cursor movement, view switches, auto-save cycles, and errors without polling or wrapping the DOM. Every event is subscribed through editor.on() and unsubscribed through editor.off().

Subscribing to Events

Use editor.on() to register a handler and editor.off() to remove it. Always hold a named reference to the callback function if you intend to unsubscribe later.
Always subscribe to the error event during development and in production. It is the only way to learn about silent failures such as image upload rejections and sanitizer errors — the editor does not throw exceptions for these conditions.

change

Fires on every content change in the editor — keystrokes, pastes, formatting commands, setHTML() calls, and undo/redo operations all trigger this event.
string
The full editor content as a sanitized HTML string at the moment of the change.

selectionchange

Fires whenever the cursor position or text selection changes inside the editor. No payload is delivered — query editor.getHTML() or inspect window.getSelection() inside the handler if you need context about the current selection.

history:change

Fires when the undo/redo stack changes — both when a new snapshot is pushed and when the user navigates the history. Use this to enable or disable custom undo/redo UI controls.

view:toggle

Fires after the editor transitions between WYSIWYG mode and raw HTML editing mode, either programmatically via toggleHtmlView() or through the built-in toolbar button.
boolean
true when the editor has just entered raw HTML mode; false when it has returned to WYSIWYG mode.

autosave

Fires after the editor successfully writes content to localStorage. This event only fires when the autoSave option is configured. No payload is delivered.
The autosave event fires after a successful write. It does not fire if localStorage is unavailable or throws (e.g. in private browsing with storage blocked). Subscribe to error to catch storage failures.

error

Fires when a recoverable error occurs inside the editor. The editor does not throw exceptions for these conditions — it emits them as events so you can decide how to surface them to the user.
string
A machine-readable error code string. See the Error codes table below.
string
A human-readable description of what went wrong.

Error Codes

The following codes appear in the error event’s code field: