Browse Source

fix: heading

Tienson Qin 2 years ago
parent
commit
3cc7977d93

+ 1 - 0
src/main/frontend/components/block.cljs

@@ -1930,6 +1930,7 @@
                       (<= heading-level 6)
                       (<= heading-level 6)
                       heading-level)
                       heading-level)
                  (pu/lookup properties :heading))
                  (pu/lookup properties :heading))
+        ;; FIXME: level is missing for db-based graphs
         heading (if (true? heading) (min (inc level) 6) heading)
         heading (if (true? heading) (min (inc level) 6) heading)
         elem (if heading
         elem (if heading
                (keyword (str "h" heading
                (keyword (str "h" heading

+ 1 - 1
src/main/frontend/components/content.cljs

@@ -36,7 +36,7 @@
   []
   []
   (let [repo (state/get-current-repo)]
   (let [repo (state/get-current-repo)]
     [:.menu-links-wrapper
     [:.menu-links-wrapper
-     (ui/menu-background-color #(property-handler/batch-add-block-property! repo (state/get-selection-block-ids) :background-color %)
+     (ui/menu-background-color #(property-handler/batch-set-block-property! repo (state/get-selection-block-ids) :background-color %)
                                #(property-handler/batch-remove-block-property! repo (state/get-selection-block-ids) :background-color))
                                #(property-handler/batch-remove-block-property! repo (state/get-selection-block-ids) :background-color))
 
 
      (ui/menu-heading #(editor-handler/batch-set-heading! (state/get-selection-block-ids) %)
      (ui/menu-heading #(editor-handler/batch-set-heading! (state/get-selection-block-ids) %)

+ 1 - 1
src/main/frontend/handler/db_based/property.cljs

@@ -260,7 +260,7 @@
                              :block/schema class-new-schema}]
                              :block/schema class-new-schema}]
           {:outliner-op :class-remove-property})))))
           {:outliner-op :class-remove-property})))))
 
 
-(defn batch-add-property!
+(defn batch-set-property!
   "Notice that this works only for properties with cardinality equals to `one`."
   "Notice that this works only for properties with cardinality equals to `one`."
   [repo block-ids k-name v]
   [repo block-ids k-name v]
   (let [k-name (name k-name)
   (let [k-name (name k-name)

+ 13 - 14
src/main/frontend/handler/editor.cljs

@@ -101,7 +101,7 @@
           repo (state/get-current-repo)]
           repo (state/get-current-repo)]
       (if has-ordered?
       (if has-ordered?
         (property-handler/batch-remove-block-property! repo blocks-uuids order-list-prop)
         (property-handler/batch-remove-block-property! repo blocks-uuids order-list-prop)
-        (property-handler/batch-add-block-property! repo blocks-uuids order-list-prop "number")))))
+        (property-handler/batch-set-block-property! repo blocks-uuids order-list-prop "number")))))
 
 
 (defn get-selection-and-format
 (defn get-selection-and-format
   []
   []
@@ -3707,26 +3707,25 @@
            :block/content content}))
            :block/content content}))
       (set-block-property-aux! repo block :heading heading))))
       (set-block-property-aux! repo block :heading heading))))
 
 
-(defn set-heading!
-  [block-id heading]
+(defn batch-set-heading!
+  [block-ids heading]
   (let [repo (state/get-current-repo)]
   (let [repo (state/get-current-repo)]
-    (when-let [block (set-heading-aux! repo block-id heading)]
+    (if (config/db-based-graph? repo)
+      (property-handler/batch-set-block-property! repo block-ids :heading heading)
       (outliner-tx/transact!
       (outliner-tx/transact!
-       {:outliner-op :save-block}
-       (outliner-core/save-block! block)))))
+        {:outliner-op :save-block}
+        (doseq [block-id block-ids]
+          (when-let [block (set-heading-aux! repo block-id heading)]
+            (outliner-core/save-block! block)))))))
+
+(defn set-heading!
+  [block-id heading]
+  (batch-set-heading! [block-id] heading))
 
 
 (defn remove-heading!
 (defn remove-heading!
   [block-id]
   [block-id]
   (set-heading! block-id nil))
   (set-heading! block-id nil))
 
 
-(defn batch-set-heading!
-  [block-ids heading]
-  (let [repo (state/get-current-repo)]
-    (outliner-tx/transact!
-     {:outliner-op :save-block}
-     (doseq [block-id block-ids]
-       (when-let [block (set-heading-aux! repo block-id heading)]
-         (outliner-core/save-block! block))))))
 
 
 (defn batch-remove-heading!
 (defn batch-remove-heading!
   [block-ids]
   [block-ids]

+ 6 - 6
src/main/frontend/handler/file_based/property.cljs

@@ -69,7 +69,7 @@
 (def goto-properties-end-when-file-based property/goto-properties-end)
 (def goto-properties-end-when-file-based property/goto-properties-end)
 (def front-matter?-when-file-based property/front-matter?)
 (def front-matter?-when-file-based property/front-matter?)
 
 
-(defn batch-set-block-property!
+(defn batch-set-block-property-aux!
   "col: a collection of [block-id property-key property-value]."
   "col: a collection of [block-id property-key property-value]."
   [col]
   [col]
   #_:clj-kondo/ignore
   #_:clj-kondo/ignore
@@ -117,20 +117,20 @@
                                      input-pos
                                      input-pos
                                      (state/get-edit-input-id)))))))
                                      (state/get-edit-input-id)))))))
 
 
-(defn batch-add-block-property!
+(defn batch-set-block-property!
   [block-ids property-key property-value]
   [block-ids property-key property-value]
-  (batch-set-block-property! (map #(vector % property-key property-value) block-ids)))
+  (batch-set-block-property-aux! (map #(vector % property-key property-value) block-ids)))
 
 
 (defn batch-remove-block-property!
 (defn batch-remove-block-property!
   [block-ids property-key]
   [block-ids property-key]
-  (batch-set-block-property! (map #(vector % property-key nil) block-ids)))
+  (batch-set-block-property! block-ids property-key nil))
 
 
 (defn remove-block-property!
 (defn remove-block-property!
   [block-id key]
   [block-id key]
   (let [key (keyword key)]
   (let [key (keyword key)]
-    (batch-set-block-property! [[block-id key nil]])))
+    (batch-set-block-property-aux! [[block-id key nil]])))
 
 
 (defn set-block-property!
 (defn set-block-property!
   [block-id key value]
   [block-id key value]
   (let [key (keyword key)]
   (let [key (keyword key)]
-    (batch-set-block-property! [[block-id key value]])))
+    (batch-set-block-property-aux! [[block-id key value]])))

+ 9 - 7
src/main/frontend/handler/property.cljs

@@ -66,19 +66,21 @@
   (when-not (config/db-based-graph? repo)
   (when-not (config/db-based-graph? repo)
     (file-property/set-block-property! block-id :id (str block-id))))
     (file-property/set-block-property! block-id :id (str block-id))))
 
 
-(defn batch-add-block-property!
-  [repo block-ids key value]
-  (if (config/db-based-graph? repo)
-    (db-property/batch-add-property! repo block-ids key value)
-    (file-property/batch-add-block-property! block-ids key value)))
-
 (defn batch-remove-block-property!
 (defn batch-remove-block-property!
   [repo block-ids key]
   [repo block-ids key]
   (if (config/db-based-graph? repo)
   (if (config/db-based-graph? repo)
     (db-property/batch-remove-property! repo block-ids key)
     (db-property/batch-remove-property! repo block-ids key)
     (file-property/batch-remove-block-property! block-ids key)))
     (file-property/batch-remove-block-property! block-ids key)))
 
 
+(defn batch-set-block-property!
+  [repo block-ids key value]
+  (if (config/db-based-graph? repo)
+    (if (nil? value)
+      (db-property/batch-remove-property! repo block-ids key)
+      (db-property/batch-set-property! repo block-ids key value))
+    (file-property/batch-set-block-property! block-ids key value)))
+
 (defn file-batch-set-property!
 (defn file-batch-set-property!
   [repo col]
   [repo col]
   (when-not (config/db-based-graph? repo)
   (when-not (config/db-based-graph? repo)
-    (file-property/batch-set-block-property! col)))
+    (file-property/batch-set-block-property-aux! col)))