getSelection
Release 2.11.0 and above.
Returns the Selection information from the editor. The Selection information contains four pieces of position information as shown below.
| Type | Description |
|---|---|
start | The starting position of the Selection in the document. |
end | The last position of the Selection in the document. |
anchor | The position where the Selection started (e.g. when clicking and dragging the mouse, the position where the mouse was clicked). |
focus | The position where the Selection ended. |
Example:
var selection = editor.getSelection();
var startPosition = selection.start;
var endPosition = selection.end;
var anchorPosition = selection.anchor;
var focusPosition = selection.focus;
Also, Selection is classified into text, cell, and drawingObject depending on the type of selected content.
Depending on the type, the content of the position information differs as shown below.
<table> <thead> <tr><th>type</th><th>position</th></tr> </thead> <tbody> <tr> <td><code>text</code></td> <td>id: Paragraph ID.
offset: The position of the selection within the paragraph.
id: The ID of the first paragraph contained in the cell.
offset: For anchor position, the position information where the Selection started within the paragraph.
tableCellId: The ID of the cell.
tableId: The ID of the table.
drawingObjectId: The ID of the drawingObject.
id: The ID of the paragraph containing the drawingObject.
offset: The position of the drawingObject within the paragraph.
The type information from the Selection can be checked as follows.
Example:
var selection = editor.getSelection();
var anchorType = selection.anchor.getType();
var focusType = selection.focus.getType();