Expand all

ve.SelectionState

Constructor

new ve.SelectionState(selection) #

Like the DOM Selection object, but not updated live from the actual selection

WARNING: the Nodes are still live and mutable, which can change the meaning of the offsets or invalidate the value of isBackwards.

Parameters:

Name Type Description
selection ve.SelectionState | Selection | Object

DOM Selection-like object

Properties:
Name Type Attributes Description
anchorNode Node | null

The anchor node (null if no selection)

anchorOffset number

The anchor offset (0 if no selection)

focusNode Node | null

The focus node (null if no selection)

focusOffset number

The focus offset (0 if no selection)

isCollapsed boolean optional

Whether the anchor and focus are the same

isBackwards boolean optional

Whether the focus is before the anchor in document order

Source:

Like the DOM Selection object, but not updated live from the actual selection

WARNING: the Nodes are still live and mutable, which can change the meaning of the offsets or invalidate the value of isBackwards.

Methods

equalsSelection(other) → {boolean} #

Whether the selection represents is the same range as another DOM Selection-like object

Parameters:

Name Type Description
other Object

DOM Selection-like object

Source:

Returns:

True if the anchors/focuses are equal (including null)

Type
boolean
Whether the selection represents is the same range as another DOM Selection-like object

flip() → {ve.SelectionState} #

Returns the selection with the anchor and focus swapped

Source:

Returns:

selection with anchor/focus swapped. Object-identical to this if isCollapsed

Type
ve.SelectionState
Returns the selection with the anchor and focus swapped

getNativeRange(doc) → {Range|null} #

Get a range representation of the selection

N.B. Range objects do not show whether the selection is backwards

Parameters:

Name Type Description
doc HTMLDocument

The owner document of the selection nodes

Source:

Returns:

Type
Range | null

Get a range representation of the selection

N.B.

newNullSelection() → {ve.SelectionState}static #

Create a selection state object representing no selection

Source:

Returns:

Object representing no selection

Type
ve.SelectionState
Create a selection state object representing no selection