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.
A Selection
represents 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.
anchorNode : Selection -> RichText.Model.Node.Path
The path to the selection anchor node
anchorOffset : Selection -> Basics.Int
The selection anchor offset
focusNode : Selection -> RichText.Model.Node.Path
The path to the selection focus node
focusOffset : Selection -> Basics.Int
The selection focus offset
caret : RichText.Model.Node.Path -> Basics.Int -> Selection
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 }
singleNodeRange : RichText.Model.Node.Path -> Basics.Int -> Basics.Int -> Selection
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 }
range : RichText.Model.Node.Path -> Basics.Int -> RichText.Model.Node.Path -> Basics.Int -> Selection
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 }
isCollapsed : Selection -> Basics.Bool
This is a helper method for determining if a selection is collapsed.
isCollapsed <| singleNodeRange [0, 1] 0 1
--> False
isCollapsed <| caret [0, 1] 0
--> True
normalize : Selection -> Selection
Sorts 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 }