Skip to content

Instantly share code, notes, and snippets.

@kolmodin
Created June 29, 2012 19:53
Show Gist options
  • Save kolmodin/3020266 to your computer and use it in GitHub Desktop.
Save kolmodin/3020266 to your computer and use it in GitHub Desktop.
Looking for idiomatic version of something like this
;; part of my 100 first lines of clojure/clojurescript
;; not finished... not working.
(defn withHints [editor hints]
(defn insert [str] (.replaceRange editor str (.-from result) (.-to result)))
(let [completions (.-list hints)]
(cond
(= 1 (.-length completions)) (insert (first completions)))
(let [complete (.createElement js/document "div")
pos (.cursorCoords editor)]
(set! (.-class complete) "goog-menu")
(set! (.-id complete) "menu")
(set! (-> complete .-style .-left) (str (.-x pos) "px"))
(set! (-> complete .-style .-top) (str (.-yBot pos) "px"))
(set! (-> complete .-style .-position) "absolute")
(doseq [i completions]
(let [e (.createElement js/document "div")]
(set! (.-innerHTML e) (str i))
(set! (.-class e) "goog-menuitem")
(set! (-> e .-style .-color) "red")
(.appendChild complete e)
)
)
(.appendChild (.-body js/document) complete)
(let [m (js/goog.ui.Menu. )]
(.decorate m complete))
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment