diff --git a/src/main/frontend/components/content.cljs b/src/main/frontend/components/content.cljs index e791732079..510d724e82 100644 --- a/src/main/frontend/components/content.cljs +++ b/src/main/frontend/components/content.cljs @@ -84,6 +84,12 @@ (t :context-menu/make-a-flashcard) nil)) + (ui/menu-link + {:key "Toggle number list" + :on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])} + (t :context-menu/toggle-number-list) + nil) + (ui/menu-link {:key "cycle todos" :on-click editor-handler/cycle-todos!} @@ -255,6 +261,12 @@ :else nil) + (ui/menu-link + {:key "Toggle number list" + :on-click #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])} + (t :context-menu/toggle-number-list) + nil) + [:hr.menu-separator] (ui/menu-link diff --git a/src/main/frontend/dicts.cljc b/src/main/frontend/dicts.cljc index 9dc17a27f0..8054b6750c 100644 --- a/src/main/frontend/dicts.cljc +++ b/src/main/frontend/dicts.cljc @@ -171,6 +171,7 @@ :content/open-in-sidebar "Open in sidebar" :content/click-to-edit "Click to edit" :context-menu/make-a-flashcard "Make a Flashcard" + :context-menu/toggle-number-list "Toggle number list" :context-menu/preview-flashcard "Preview Flashcard" :context-menu/make-a-template "Make a Template" :context-menu/input-template-name "What's the template's name?" diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 4308257eab..11272a5561 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -64,6 +64,8 @@ (declare set-block-property!) (declare remove-block-property!) +(declare batch-add-block-property!) +(declare batch-remove-block-property!) (defn get-block-own-order-list-type [block] @@ -87,6 +89,16 @@ [block] (some-> block (set-block-own-order-list-type! "number"))) +(defn toggle-blocks-as-own-order-list! + [blocks] + (when (seq blocks) + (let [has-ordered? (some own-order-number-list? blocks) + blocks-uuids (some->> blocks (map :block/uuid) (remove nil?)) + order-list-prop :logseq.order-list-type] + (if has-ordered? + (batch-remove-block-property! blocks-uuids order-list-prop) + (batch-add-block-property! blocks-uuids order-list-prop "number"))))) + (defn get-selection-and-format [] (when-let [block (state/get-edit-block)] diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 4a66b41117..b7eb29e58d 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -948,11 +948,17 @@ (defmethod handle :editor/quick-capture [[_ args]] (quick-capture/quick-capture args)) -(defmethod handle :editor/toggle-own-number-list [[_ block]] - (when block - (if (editor-handler/own-order-number-list? block) - (editor-handler/remove-block-own-order-list-type! block) - (editor-handler/make-block-as-own-order-list! block)))) +(defmethod handle :editor/toggle-own-number-list [[_ blocks]] + (let [batch? (sequential? blocks) + blocks (cond->> blocks + batch? + (map #(cond-> % (or (uuid? %) (string? %)) (db-model/get-block-by-uuid))))] + (if (and batch? (> (count blocks) 1)) + (editor-handler/toggle-blocks-as-own-order-list! blocks) + (when-let [block (cond-> blocks batch? (first))] + (if (editor-handler/own-order-number-list? block) + (editor-handler/remove-block-own-order-list-type! block) + (editor-handler/make-block-as-own-order-list! block)))))) (defmethod handle :editor/remove-own-number-list [[_ block]] (when (some-> block (editor-handler/own-order-number-list?))