new Selection()
The document selection.
Methods
-
<static> createAroundNode(node)
-
Create a selection around the given node.
Parameters:
Name Type Description node
sync.api.dom.Node The node which selection should wrap. - Deprecated:
Returns:
The selection object.- Type
- sync.api.Selection
-
<static> createEmptySelectionInNode(node, pos)
-
Returns a selection that is empty and is located inside the given node, at the given position.
Parameters:
Name Type Description node
sync.api.dom.Node The element, comment or PI in which the selection is positioned. pos
string The position of the caret: - 'before' means before all children nodes
- 'after' that means after all children nodes
- Deprecated:
Returns:
The selection.- Type
- sync.api.Selection
-
<static> createEmptySelectionRelativeToNode(node, offset [, opt_fromNodeEndTag])
-
Creates an empty selection at a position that is "offset" steps to the right of the start/end tag of the given "node". A step means either a content character, a start tag of a node or an end tag of a node. For example, with this XML content:
<p>I <b>like</b> XML.</p>
The following call:sync.api.Selection.createEmptySelectionRelativeToNode(p, 5, true)
Creates a position in the word "like" as presented below:<p>I <b>li|ke</b> XML.</p>
Parameters:
Name Type Argument Description node
sync.api.dom.Node The element, comment or PI used as a reference for the selection position. offset
number The number of steps to the right of the start/end tag of the reference node. opt_fromNodeEndTag
boolean <optional>
true, to create the selection relative to the end tag of the given node rather than to its start. - Deprecated:
-
equals(sel)
-
Compare this selection with the given one.
Parameters:
Name Type Description sel
sync.api.Selection The selection to compare with. Returns:
true if the two selection are equal.- Type
- boolean
-
extendedTo(node, offset [, opt_fromNodeEndTag])
-
Returns a new selection which is created by extending the current selection to the position that is "offset" steps to the right of the start/end tag of the given "node". A step means either a content character, a start tag of a node or an end tag of a node. For example, with this XML content, and the selection represented as a vertical line:
<p>I <b>|like</b> XML.</p>
The following call:var extendedSel = sel.extendedTo(p, 7, true)
creates a new extended selection to select the word "like" as presented below:<p>I <b>|like|</b> XML.</p>
Parameters:
Name Type Argument Description node
sync.api.dom.Node The element, comment, or PI used as a reference for the selection position. offset
number The number of steps to the right of the start/end tag of the reference node. opt_fromNodeEndTag
boolean <optional>
true, to create the selection relative to the end tag of the given node rather than to its start. Returns:
- Type
- sync.api.Selection
-
getBoundingClientRect()
-
Computes the bounding rectangle of the selection.
Returns:
Bounding rectangle ornull
if it cannot be computed. Its position is relative to the viewport.- Type
- sync.api.math.Rect | null
-
getCaretPositionInformation()
-
Retrieve information about the caret position. This may be used to check if caret is placed on a tag.
Returns:
Information about caret position. -
getFullySelectedNode()
-
Returns the element, comment or PI that is fully selected.
Returns:
The element, comment or PI which is fully selected.- Type
- sync.api.dom.Node
-
getNodeAtCaret( [opt_includeTextNodes])
-
Returns the node at caret if the selection is empty.
Parameters:
Name Type Argument Description opt_includeTextNodes
boolean <optional>
If present and true
will include text nodes. By default text nodes are ignored.Returns:
The node at caret if the selection is empty.- Type
- sync.api.dom.Node | null
-
getNodeAtSelection( [opt_includeTextNodes])
-
Returns the node at the current selection.
If the current selection is empty, the node in which the selection resides is returned.
If the selection is around an entire node, that node will be returned.
If the selection spans multiple nodes, the node where the selection has ended is returned.
Parameters:
Name Type Argument Description opt_includeTextNodes
boolean <optional>
If present and true
will include text nodes. By default text nodes are ignored.Returns:
The node at the current selection.- Type
- sync.api.dom.Node
-
getNodeAtSelectionEnd( [opt_includeTextNodes])
-
Returns the node at the current selection.
If the current selection is empty, the node in which the selection resides is returned.
If the selection is around an entire node, that node will be returned.
If the selection spans multiple nodes, the node at the end of it.
Parameters:
Name Type Argument Description opt_includeTextNodes
boolean <optional>
If present and true
will include text nodes. By default text nodes are ignored.Returns:
The node at the current selection.- Type
- sync.api.dom.Node
-
getNodeAtSelectionStart( [opt_includeTextNodes])
-
Returns the node at the current selection.
If the current selection is empty, the node in which the selection resides is returned.
If the selection is around an entire node, that node will be returned.
If the selection spans multiple nodes, the node at the start of it.
Parameters:
Name Type Argument Description opt_includeTextNodes
boolean <optional>
If present and true
will include text nodes. By default text nodes are ignored.Returns:
The node at the current selection.- Type
- sync.api.dom.Node
-
isEmpty()
-
Checks whether the selection is empty.
Returns:
true if the selection is empty.- Type
- boolean