Quellcode durchsuchen

fix: can't paste asset

fixes https://github.com/logseq/db-test/issues/575
Tienson Qin vor 3 Wochen
Ursprung
Commit
2140029c60

+ 11 - 4
deps/outliner/src/logseq/outliner/core.cljs

@@ -795,7 +795,7 @@
                                 :or {update-timestamps? true}}]
   {:pre [(seq blocks)
          (m/validate block-map-or-entity target-block)]}
-  (let [blocks (->>
+  (let [blocks (cond->>
                 (keep (fn [b]
                         (if-let [eid (or (:db/id b)
                                          (when-let [id (:block/uuid b)]
@@ -813,7 +813,9 @@
                             (apply dissoc b' dissoc-keys))
                           b))
                       blocks)
-                (remove ldb/asset?))
+                 (or (= outliner-op :paste)
+                     insert-template?)
+                 (remove ldb/asset?))
         [target-block sibling?] (get-target-block db blocks target-block opts)
         _ (assert (some? target-block) (str "Invalid target: " target-block))
         replace-empty-target? (if (and (some? replace-empty-target?)
@@ -1161,7 +1163,10 @@
           (insert-blocks repo @conn blocks target-block opts))]
   (defn insert-blocks!
     [repo conn blocks target-block opts]
-    (op-transact! :insert-blocks f repo conn blocks target-block (assoc opts :outliner-op :insert-blocks))))
+    (op-transact! :insert-blocks f repo conn blocks target-block
+                  (if (:outliner-op opts)
+                    opts
+                    (assoc opts :outliner-op :insert-blocks)))))
 
 (let [f (fn [_repo conn blocks _opts]
           (delete-blocks @conn blocks))]
@@ -1172,7 +1177,9 @@
 (defn move-blocks!
   [repo conn blocks target-block opts]
   (op-transact! :move-blocks move-blocks repo conn blocks target-block
-                (assoc opts :outliner-op :move-blocks)))
+                (if (:outliner-op opts)
+                  opts
+                  (assoc opts :outliner-op :move-blocks))))
 
 (defn move-blocks-up-down!
   [repo conn blocks up?]

+ 6 - 3
src/main/frontend/handler/editor.cljs

@@ -326,7 +326,7 @@
 (declare save-current-block!)
 (defn outliner-insert-block!
   [config current-block new-block {:keys [sibling? keep-uuid? ordered-list?
-                                          replace-empty-target?]}]
+                                          replace-empty-target? outliner-op]}]
   (let [ref-query-top-block? (and (or (:ref? config)
                                       (:custom-query? config))
                                   (not (:ref-query-child? config)))
@@ -359,7 +359,8 @@
      (outliner-op/insert-blocks! [new-block'] current-block {:sibling? sibling?
                                                              :keep-uuid? keep-uuid?
                                                              :ordered-list? ordered-list?
-                                                             :replace-empty-target? replace-empty-target?}))))
+                                                             :replace-empty-target? replace-empty-target?
+                                                             :outliner-op outliner-op}))))
 
 (defn- block-self-alone-when-insert?
   [config uuid]
@@ -559,7 +560,8 @@
   [content {:keys [page block-uuid
                    sibling? before? start? end?
                    properties
-                   custom-uuid replace-empty-target? edit-block? ordered-list? other-attrs]
+                   custom-uuid replace-empty-target? edit-block? ordered-list? other-attrs
+                   outliner-op]
             :or {sibling? false
                  before? false
                  edit-block? true}
@@ -640,6 +642,7 @@
                                         {:sibling? sibling?
                                          :keep-uuid? true
                                          :ordered-list? ordered-list?
+                                         :outliner-op outliner-op
                                          :replace-empty-target? replace-empty-target?})))
              (when edit-block?
                (if (and replace-empty-target?

+ 1 - 0
src/main/frontend/handler/paste.cljs

@@ -213,6 +213,7 @@
                     (editor-handler/api-insert-new-block! ""
                                                           {:block-uuid (:block/uuid current-block)
                                                            :sibling? true
+                                                           :outliner-op :paste
                                                            :replace-empty-target? true
                                                            :other-attrs {:block/link (:db/id (db/entity [:block/uuid block-id]))}})
                     (state/clear-edit!)))))