(defn
init
[paren-soup opts]
(.init js/rangy)
(let
[opts
(js->clj opts :keywordize-keys true)
content
(.querySelector paren-soup ".content")
events-chan
(chan)
editor
(create-editor paren-soup content events-chan opts)]
(set! (.-spellcheck paren-soup) false)
(when-not
content
(throw (js/Error. "Can't find a div with class 'content'")))
(initialize! editor)
(add-event-listeners! content events-chan opts)
(go
(while
true
(let
[event (<! events-chan)]
(when-not
(some->
opts
:before-change-callback
((fn* [p1__18525#] (p1__18525# event))))
(case
(.-type event)
"keydown"
(cond
(and
(key-name? event :undo-or-redo)
(-> opts :disable-undo-redo? not))
(if (.-shiftKey event) (redo! editor) (undo! editor))
(key-name? event :enter)
(enter! editor)
(key-name? event :up-arrow)
(up! editor)
(key-name? event :down-arrow)
(down! editor)
(key-name? event :tab)
(tab! editor))
"keyup"
(cond
(key-name? event :arrows)
(update-cursor-position!
editor
(dom/get-cursor-position content false))
(key-name? event :general)
(refresh-after-key-event! editor event))
"cut"
(refresh-after-cut-paste! editor)
"paste"
(refresh-after-cut-paste! editor)
"mouseup"
(update-cursor-position!
editor
(dom/get-cursor-position
content
(some? (:console-callback opts))))
"mouseenter"
(show-error-message! paren-soup event)
"mouseleave"
(hide-error-messages! paren-soup)
nil)
(some->
opts
:change-callback
((fn* [p1__18526#] (p1__18526# event))))))))
editor))