Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facets #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions css/keymapper.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
max-width: 256px;
}

#keymapper h2 {
font-size: large;
}

#keymapper ul li .command {
border-left: 1px solid black;
display: inline-block;
Expand All @@ -33,3 +37,4 @@
#keymapper ul li .command span + span {
display: block;
}

44 changes: 40 additions & 4 deletions src/lt/plugins/keymapper.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@
[crate.binding :refer [bound]])
(:require-macros [lt.macros :refer [defui behavior]]))


(defn- separate [f seq]
[(filter f seq)
(filter (complement f) seq)])

(def facets
(atom [{:name "All"
:matchers [#"."]}]))

(defn put-items-into-facets [items facets]
(loop [processed [], items items
[{:as h :keys [matchers]} & tail :as unprocessed]
(->> facets (map (partial conj {:matched []}))
(sort-by :eval-order))]
(if (empty? unprocessed) (sort-by :display-order processed)
(let [matcher #(some (fn [x y] (re-find x %)) matchers) ;; TODO generic function
[match nope] (separate matcher items)]
(recur (conj processed (assoc h :matched match)) nope tail)))))

(defui keymap-item [this item]
(let [keys (first item)
cmds (second item)]
Expand All @@ -19,13 +38,22 @@
[:span (print-str cmd) " "])
cmds)]]))

(defui keymap-facets [this items]
[:div {:id "facets"}
(for [{:keys [name matched hide]} (put-items-into-facets items @facets)]
(when (not hide)
[:div {:class "facet"}
[:h2 (str name " - " (count matched))]
[:ul.keymapper-list (map (partial keymap-item this) matched)]]))])

(defui keymap-list [this keys]
[:ul.keymapper-list (map (partial keymap-item this) keys)])

(defui keymap-panel [this]
[:div {:id "keymapper"}
[:h1 "Keymapper" ]
[:ul.keymapper-list]])
[:h1 "Keymaps" ]
[:div {:id "facets"}
"loading..."]])

(object/object* ::keymapper
:tags [:keymapper]
Expand All @@ -37,8 +65,8 @@
:triggers #{:update!}
:debounce 200
:reaction (fn [this keys]
(dom/replace-with (dom/$ :.keymapper-list (object/->content this))
(keymap-list this keys))))
(dom/replace-with (dom/$ :div#facets (object/->content this))
(keymap-facets this keys))))

(behavior ::unwatch
:triggers #{::unwatch}
Expand All @@ -63,6 +91,14 @@
(object/raise this ::unwatch)
(tabs/rem! this)))

(behavior ::set-facets!
:triggers #{:object.instant}
:desc "set facets to the provided"
:type :user
:exclusive [:lt.plugins.keymapper/set-facets!]
:reaction (fn [_ f]
(reset! facets f)))

(def keymapper (object/create ::keymapper))

(cmd/command {:command :keymapper.show
Expand Down