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.

TypeDescription
startThe starting position of the Selection in the document.
endThe last position of the Selection in the document.
anchorThe position where the Selection started (e.g. when clicking and dragging the mouse, the position where the mouse was clicked).
focusThe 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.

</td> </tr> <tr> <td><code>cell</code></td> <td>

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.

</td> </tr> <tr> <td><code>drawingObject</code></td> <td>

drawingObjectId: The ID of the drawingObject.

id: The ID of the paragraph containing the drawingObject.

offset: The position of the drawingObject within the paragraph.

</td> </tr> </tbody> </table>

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();