2 Editor API
Jiuqing Song редактировал(а) эту страницу 2019-02-02 16:16:21 -08:00

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

Node API

insertNode

Insert node into editor with the given options.

deleteNode

Delete a node from editor

replaceNode

Replace a node in editor content with another node

getInlineElementAtNode

Get InlineElement at given node

getBlockElementAtNode

Get BlockElement at given node

contains

Check if the node/range falls in the editor content

queryElements

Query HTML elements in editor by a selector string

collapseNodes

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

Content API

isEmpty

Check whether the editor contains any visible content

getContent

Get current editor content as HTML string

getTextContent

Get plain text content inside editor

setContent

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

insertContent

Insert HTML content into editor

Selection API

getSelectionRange

Get current selection range from Editor.

hasFocus

Check if focus is in editor now

focus

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

select

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

getSelection

Get current selection object from the window which contains the editor

saveSelectionRange

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

restoreSavedRange

Restore the saved selection range and clear it

getFocusedPosition

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

getCursorRect

Get a rect representing the location of the cursor.

getElementAtCursor

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

addDomEventHandler

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

triggerEvent

Trigger an event to be dispatched to all plugins

triggerContentChangedEvent

Trigger a ContentChangedEvent

Undo API

undo

Undo last edit operation

redo

Redo next edit operation

addUndoSnapshot

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

performAutoComplete

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

canUndo

Whether there is an available undo snapshot

canRedo

Whether there is an available redo snapshot

Misc

getDocument

Get document which contains this editor

getCustomData

Get custom data related to this editor

isInIME

Check if editor is in IME input sequence

getDefaultFormat

Get default format of this editor

getBodyTraverser

Get a content traverser for the whole editor

getSelectionTraverser

Get a content traverser for current selection

getBlockTraverser

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

runAsync

Run a callback function asynchronously

setEditorDomAttribute

Set DOM attribute of editor content DIV

addContentEditFeature

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