-
Notifications
You must be signed in to change notification settings - Fork 164
Plugin events
Jiuqing Song edited this page Mar 9, 2018
·
5 revisions
Go back to Create your own plugin
Editor Plugin handles events in onPluginEvent() method. It takes an object which implements PluginEvent interface:
interface PluginEvent {
eventType: PluginEventType;
eventDataCache?: { [key: string]: any };
}
eventType
is an enum to tell which type of event it is. It has the following values:
const enum PluginEventType {
KeyDown,
KeyPress,
KeyUp,
CompositionEnd,
MouseDown,
MouseUp,
ContentChanged,
ExtractContent,
BeforePaste,
}
The first 6 event types are mapped to DOM events. They are triggered when related DOM event happens inside editor. Editor plugin can handle these event by checking the event type, and cast the event object into PluginDomEvent
in order to get the raw DOM Event object.
The other 3 events are triggered when somewhere calls editor.triggerEvent() API. Each of these event type is mapped to a related PluginEvent interface. For a detailed mapping, please reference to the table below:
PluginEventType | PluginEvent object interface | DOMEvent | Trigger |
---|---|---|---|
KeyDown | PluginDomEvent | keydown | Browser DOM Event |
KeyPress | PluginDomEvent | keypress | Browser DOM Event |
KeyUp | PluginDomEvent | keyup | Browser DOM Event |
CompositionEnd | PluginDomEvent | compositionend | Browser DOM Event |
MouseDown | PluginDomEvent | mousedown | Browser DOM Event |
MouseUp | PluginDomEvent | mouseup | Browser DOM Event |
ContentChanged | ContentChangedEvent | - | setContent, undo, paste, ... |
ExtractContent | ExtractContentEvent | - | getContent |
BeforePaste | BeforePasteEvent | - | paste |