A selection represents the information received and translated from the selection web API. Note that the anchorNode and focusNode are translations of the node paths relative to the editor.
The path to the selection anchor node
The selection anchor offset
The selection focus offset
This is a helper method for constructing a caret selection.
caret [0, 1] 0
--> Creates a selection with { anchorNode=[0,1], anchorOffset=0, focusNode=[0,1], focusOffset=0 }This is a helper method for creating a selection over a single node
singleNodeRange [0, 1] 0 1
--> Creates a selection with { anchorNode=[0,1], anchorOffset=0, focusNode=[0,1], focusOffset=1 }This is a helper method for creating a range selection
range [0, 1] 0 [1, 1] 1
--> Creates a selection with { anchorNode=[0,1], anchorOffset=0, focusNode=[1,1], focusOffset=1 }This is a helper method for determining if a selection is collapsed.
isCollapsed <| singleNodeRange [0, 1] 0 1
--> False
isCollapsed <| caret [0, 1] 0
--> TrueSorts the selection's anchor to be before the focus. This method is helpful because in the selection API, a selection's anchor node is not always before a selection's focus node, but when reasoning about editor operations, we want the anchor to be before the focus.
normalize <| range [ 1, 1 ] 0 [ 0, 1 ] 1
--> { anchorNode=[0,1], anchorOffset=1, focusNode=[1,1], focusOffset=0 }
normalize <| singleNodeRange [0, 1] 1 0
--> { anchorNode=[0,1], anchorOffset=0, focusNode=[0,1], focusOffset=1 }
A
Selectionrepresents the information received and translated from the selection API. Note that the anchorNode and focusNode are translations of the node paths relative to the editor.