From 5efd73b4426a3c6a00561acdfd9db53f7c50c5eb Mon Sep 17 00:00:00 2001 From: rcmerci Date: Thu, 15 Jul 2021 17:58:54 +0800 Subject: [PATCH] add card-query, cloze slash commands --- src/main/frontend/commands.cljs | 7 +++++++ src/main/frontend/extensions/srs.cljs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/commands.cljs b/src/main/frontend/commands.cljs index e669d50bc..a86ddd660 100644 --- a/src/main/frontend/commands.cljs +++ b/src/main/frontend/commands.cljs @@ -37,6 +37,11 @@ :id :label :placeholder "Label"}]]]) +(def *extend-slash-commands (atom [])) + +(defn register-slash-command [cmd] + (swap! *extend-slash-commands conj cmd)) + (defn ->marker [marker] [[:editor/clear-current-slash] @@ -266,7 +271,9 @@ ["Embed Vimeo Video" [[:editor/input "{{vimeo }}" {:last-pattern slash :backward-pos 2}]]]] + @*extend-slash-commands ;; Allow user to modify or extend, should specify how to extend. + (state/get-commands) (state/get-plugins-commands)) (remove nil?) diff --git a/src/main/frontend/extensions/srs.cljs b/src/main/frontend/extensions/srs.cljs index 32796ca66..c1fcd3572 100644 --- a/src/main/frontend/extensions/srs.cljs +++ b/src/main/frontend/extensions/srs.cljs @@ -14,6 +14,7 @@ [frontend.ui :as ui] [frontend.format.mldoc :as mldoc] [frontend.date :as date] + [frontend.commands :as commands] [cljs-time.core :as t] [cljs-time.local :as tl] [cljs-time.coerce :as tc] @@ -512,8 +513,7 @@ [:a.open-block-ref-link.bg-base-2.text-sm.ml-2 {:title "overdue / new / total\nclick to refresh count" :on-click #(swap! (::need-requery state) (fn [o] (not o)))} - (let [_ (println "xxxxx" @*query-result) - group-by-repeat (card-group-by-repeat (mapv ->card (flatten @*query-result))) + (let [group-by-repeat (card-group-by-repeat (mapv ->card (flatten @*query-result))) new-card-count (count (flatten (vals (filterv (fn [[k _]] (< k 1))))))] ; repeats < 1 (str (count sched-blocks) "/" new-card-count "/" (count (flatten @*query-result))))]]])) @@ -526,3 +526,12 @@ card-next-schedule-property card-last-easiness-factor-property card-last-score-property}) + +;;; register slash commands +(commands/register-slash-command ["Card Query" + [[:editor/input "{{card-query }}" {:backward-pos 2}]] + "Create a card query"]) + +(commands/register-slash-command ["Cloze" + [[:editor/input "{{cloze }}" {:backward-pos 2}]] + "Create a cloze"])