Browse Source

fix: create new text block when invoking /template

Tienson Qin 7 months ago
parent
commit
aff24f2de1

+ 13 - 10
deps/outliner/src/logseq/outliner/core.cljs

@@ -643,7 +643,18 @@
                                   :or {update-timestamps? true}}]
   {:pre [(seq blocks)
          (m/validate block-map-or-entity target-block)]}
-  (let [blocks (map (fn [b] (dissoc b :block/tx-id :block/refs :block/path-refs :logseq.property/created-by)) blocks)
+  (let [blocks (keep (fn [b]
+                       (when-let [eid (or (:db/id b)
+                                          (when-let [id (:block/uuid b)]
+                                            [:block/uuid id]))]
+                         (->
+                          (if-let [e (d/entity @conn eid)]
+                            (assoc (into {} e)
+                                   :db/id (:db/id e)
+                                   :block/title (or (:block/raw-title e) (:block/title e)))
+                            b)
+                          (dissoc :block/tx-id :block/refs :block/path-refs))))
+                     blocks)
         [target-block sibling?] (get-target-block @conn blocks target-block opts)
         _ (assert (some? target-block) (str "Invalid target: " target-block))
         sibling? (if (ldb/page? target-block) false sibling?)
@@ -702,15 +713,7 @@
                                         (:db/id e)))]
                        (walk/prewalk
                         (fn [f]
-                          (cond
-                            (and (coll? f) (every? de/entity? f))
-                            (map ->new-id f)
-
-                            (de/entity? f)
-                            (->new-id f)
-
-                            :else
-                            f))
+                          (if (de/entity? f) (->new-id f) f))
                         full-tx))]
         {:tx-data full-tx'
          :blocks  tx}))))

+ 2 - 2
src/main/frontend/db/model.cljs

@@ -424,9 +424,9 @@ independent of format as format specific heading characters are stripped"
           (db-utils/pull-many repo '[*] ids'))))))
 
 (defn get-block-and-children
-  [repo block-uuid]
+  [repo block-uuid & {:as opts}]
   (let [db (conn/get-db repo)]
-    (ldb/get-block-and-children db block-uuid)))
+    (ldb/get-block-and-children db block-uuid opts)))
 
 (defn get-file-page
   ([file-path]

+ 7 - 5
src/main/frontend/handler/editor.cljs

@@ -2230,7 +2230,7 @@
                format (get block :block/format :markdown)
                block-uuid (:block/uuid block)
                template-including-parent? (not (false? (:template-including-parent (:block/properties block))))
-               blocks (db/get-block-and-children repo block-uuid)
+               blocks (db/get-block-and-children repo block-uuid {:include-property-block? true})
                sorted-blocks (if db?
                                (let [blocks' (rest blocks)]
                                  (cons
@@ -2260,9 +2260,11 @@
                                           template/resolve-dynamic-template!))
                  page (if (:block/name block) block
                           (when target (:block/page (db/entity (:db/id target)))))
-                 blocks' (map (fn [block]
-                                (paste-block-cleanup repo block page exclude-properties format content-update-fn false))
-                              blocks)
+                 blocks' (if (config/db-based-graph?)
+                           blocks
+                           (map (fn [block]
+                                  (paste-block-cleanup repo block page exclude-properties format content-update-fn false))
+                                blocks))
                  sibling? (:sibling? opts)
                  sibling?' (cond
                              (some? sibling?)
@@ -2280,7 +2282,7 @@
                                   :created-from-journal-template? journal?}
                                  (when-not (string/blank? (state/get-edit-content))
                                    (save-current-block!))
-                                 (outliner-op/insert-blocks! (map #(assoc (into {} %) :db/id (:db/id %)) blocks') target
+                                 (outliner-op/insert-blocks! blocks' target
                                                              (assoc opts :sibling? sibling?')))]
                    (when result (edit-last-block-after-inserted! (ldb/read-transit-str result))))