Created
June 28, 2014 15:53
-
-
Save alandipert/5a5a7640fc2c05d00c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn make-page | |
[text form-zippers] | |
(flow/build-dataflow | |
[(flow/cell :source cursor 0) | |
(flow/cell :source zippers form-zippers) | |
(flow/cell current-zipper (get ?zippers ?cursor)) | |
(flow/cell printed-zippers (mapv (comp print-clojure z/root) ?zippers)) | |
(flow/cell strings (mapv str ?printed-zippers)) | |
(flow/cell offsets (vec (cons 0 (reductions + (map (comp inc count) ?strings))))) | |
(flow/cell current-printed (?printed-zippers ?cursor)) | |
(flow/cell highlight-bounds | |
(->> (z/node ?current-zipper) | |
(bounds ?current-printed) | |
((juxt :start :end)) | |
(mapv (partial + (get ?offsets ?cursor))))) | |
(flow/cell top? (identical? (z/root ?current-zipper) (z/node ?current-zipper))) | |
(flow/cell insert! (.setText text (apply str (interpose \newline ?strings)))) | |
(flow/cell highlight! (apply highlight! text ?highlight-bounds)) | |
(flow/cell debug! (pp/pprint | |
(hash-map :node (z/node ?current-zipper) | |
:bounds ?highlight-bounds)))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment