Class: Selection

sync.api.Selection

new Selection()

The browser selection.
Source:

Methods

(static) createAroundNode(node) → {sync.api.Selection}

Create a selection around the given node.
Parameters:
Name Type Description
node sync.api.dom.Node The node which selection should wrap.
Source:
Returns:
The selection object.
Type
sync.api.Selection

(static) createEmptySelectionInNode(node, pos) → {sync.api.Selection}

Returns an object that represents a selection that is empty and is located inside the given node, at a position specified by the second parameter.
Parameters:
Name Type Description
node sync.api.dom.Node The node 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
Source:
Returns:
The selection.
Type
sync.api.Selection

(static) createEmptySelectionRelativeToNode(node, offset, opt_fromNodeEndTagopt)

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 Attributes Description
node sync.api.dom.Node The XML node 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.
Source:

extendTo(node, offset, opt_fromNodeEndTagopt)

Extends the 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: sel.extendTo(p, 7, true) extends the selection to select the word "like" as presented below: <p>I <b>|like|</b> XML.</p>
Parameters:
Name Type Attributes Description
node sync.api.dom.Node The XML node 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.
Source:

getFullySelectedNode() → {sync.api.dom.Node}

Returns the node that is fully selected.
Source:
Returns:
The node which is fully selected.
Type
sync.api.dom.Node

getNodeAtCaret() → {sync.api.dom.Node}

Returns the node at caret if the selection is empty.
Source:
Returns:
The node at caret if the selection is empty.
Type
sync.api.dom.Node

getNodeAtSelection() → {sync.api.dom.Node}

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.

Source:
Returns:
The node at the current selection.
Type
sync.api.dom.Node

isEmpty() → {boolean}

Checks whether the selection is empty.
Source:
Returns:
true if the selection is empty.
Type
boolean