Skip to content

Editor API

Jiuqing Song edited this page Feb 3, 2019 · 2 revisions

Editor API are public methods of Editor class. They are grouped into 6 categories:

Node API

Insert node into editor with the given options.

Delete a node from editor

Replace a node in editor content with another node

Get InlineElement at given node

Get BlockElement at given node

Check if the node/range falls in the editor content

Query HTML elements in editor by a selector string

Collapse nodes within the given start and end nodes to their common ascenstor node,

Content API

Check whether the editor contains any visible content

Get current editor content as HTML string

Get plain text content inside editor

Set HTML content to this editor. All existing content will be replaced. A ContentChanged event will be triggered

Insert HTML content into editor

Selection API

Get current selection range from Editor.

Check if focus is in editor now

Focus to this editor, the selection was restored to where it was before, no unexpected scroll.

Set selection of editor, using the provided information, such as a Position, a Range, or node and offset.

Get current selection object from the window which contains the editor

Save the current selection in editor so that when focus again, the selection can be restored

Restore the saved selection range and clear it

Get current focused position. Return null if editor doesn't have focus at this time.

Get a rect representing the location of the cursor.

Get an HTML element from current cursor position. When expectedTags is not specified, return value is the current node (if it is HTML element) or its parent node (if current node is a Text node). When expectedTags is specified, return value is the first anscestor of current node which has one of the expected tags. If no element found within editor by the given tag, return null.

Event API

Add a custom DOM event handler to handle events not handled by roosterjs. Caller need to take the responsibility to dispose the handler properly

Trigger an event to be dispatched to all plugins

Trigger a ContentChangedEvent

Undo API

Undo last edit operation

Redo next edit operation

Add undo snapshot, and execute a format callback function, then add another undo snapshot, then trigger ContentChangedEvent with given change source. If this function is called nested, undo snapshot will only be added in the outside one

Perform an auto complete action in the callback, save a snapsnot of content before the action, and trigger ContentChangedEvent with the change source if specified

Whether there is an available undo snapshot

Whether there is an available redo snapshot

Misc

Get document which contains this editor

Get custom data related to this editor

Check if editor is in IME input sequence

Get default format of this editor

Get a content traverser for the whole editor

Get a content traverser for current selection

Get a content traverser for current block element start from specified position

[https://microsoft.github.io/roosterjs/docs/classes/roosterjs_editor_core.editor.html#getcontentsearcherofcursor]

Get a text traverser of current selection

Run a callback function asynchronously

Set DOM attribute of editor content DIV

Add a Content Edit feature. This is mostly called from ContentEdit plugin

Clone this wiki locally