(defn
init-state
"Returns the editor's state. If full-selection? is true, it will try to save\nthe entire selection rather than just the cursor position."
[content crop? full-selection?]
(let
[selection
(.getSelection js/rangy)
anchor
(.-anchorNode selection)
focus
(.-focusNode selection)
parent
(when (and anchor focus) (dom/common-ancestor anchor focus))
state
{:cursor-position
(-> content (dom/get-selection full-selection?) :cursor-position),
:text (.-textContent content)}]
(if-let
[cropped-selection (some-> parent (dom/get-selection false))]
(if
crop?
(assoc
state
:cropped-state
(assoc cropped-selection :text (.-textContent parent)))
state)
state)))