Skip to content

Commit 2140029

Browse files
committed
fix: can't paste asset
fixes logseq/db-test#575
1 parent 820b2f0 commit 2140029

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

deps/outliner/src/logseq/outliner/core.cljs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@
795795
:or {update-timestamps? true}}]
796796
{:pre [(seq blocks)
797797
(m/validate block-map-or-entity target-block)]}
798-
(let [blocks (->>
798+
(let [blocks (cond->>
799799
(keep (fn [b]
800800
(if-let [eid (or (:db/id b)
801801
(when-let [id (:block/uuid b)]
@@ -813,7 +813,9 @@
813813
(apply dissoc b' dissoc-keys))
814814
b))
815815
blocks)
816-
(remove ldb/asset?))
816+
(or (= outliner-op :paste)
817+
insert-template?)
818+
(remove ldb/asset?))
817819
[target-block sibling?] (get-target-block db blocks target-block opts)
818820
_ (assert (some? target-block) (str "Invalid target: " target-block))
819821
replace-empty-target? (if (and (some? replace-empty-target?)
@@ -1161,7 +1163,10 @@
11611163
(insert-blocks repo @conn blocks target-block opts))]
11621164
(defn insert-blocks!
11631165
[repo conn blocks target-block opts]
1164-
(op-transact! :insert-blocks f repo conn blocks target-block (assoc opts :outliner-op :insert-blocks))))
1166+
(op-transact! :insert-blocks f repo conn blocks target-block
1167+
(if (:outliner-op opts)
1168+
opts
1169+
(assoc opts :outliner-op :insert-blocks)))))
11651170

11661171
(let [f (fn [_repo conn blocks _opts]
11671172
(delete-blocks @conn blocks))]
@@ -1172,7 +1177,9 @@
11721177
(defn move-blocks!
11731178
[repo conn blocks target-block opts]
11741179
(op-transact! :move-blocks move-blocks repo conn blocks target-block
1175-
(assoc opts :outliner-op :move-blocks)))
1180+
(if (:outliner-op opts)
1181+
opts
1182+
(assoc opts :outliner-op :move-blocks))))
11761183

11771184
(defn move-blocks-up-down!
11781185
[repo conn blocks up?]

src/main/frontend/handler/editor.cljs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
(declare save-current-block!)
327327
(defn outliner-insert-block!
328328
[config current-block new-block {:keys [sibling? keep-uuid? ordered-list?
329-
replace-empty-target?]}]
329+
replace-empty-target? outliner-op]}]
330330
(let [ref-query-top-block? (and (or (:ref? config)
331331
(:custom-query? config))
332332
(not (:ref-query-child? config)))
@@ -359,7 +359,8 @@
359359
(outliner-op/insert-blocks! [new-block'] current-block {:sibling? sibling?
360360
:keep-uuid? keep-uuid?
361361
:ordered-list? ordered-list?
362-
:replace-empty-target? replace-empty-target?}))))
362+
:replace-empty-target? replace-empty-target?
363+
:outliner-op outliner-op}))))
363364

364365
(defn- block-self-alone-when-insert?
365366
[config uuid]
@@ -559,7 +560,8 @@
559560
[content {:keys [page block-uuid
560561
sibling? before? start? end?
561562
properties
562-
custom-uuid replace-empty-target? edit-block? ordered-list? other-attrs]
563+
custom-uuid replace-empty-target? edit-block? ordered-list? other-attrs
564+
outliner-op]
563565
:or {sibling? false
564566
before? false
565567
edit-block? true}
@@ -640,6 +642,7 @@
640642
{:sibling? sibling?
641643
:keep-uuid? true
642644
:ordered-list? ordered-list?
645+
:outliner-op outliner-op
643646
:replace-empty-target? replace-empty-target?})))
644647
(when edit-block?
645648
(if (and replace-empty-target?

src/main/frontend/handler/paste.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
(editor-handler/api-insert-new-block! ""
214214
{:block-uuid (:block/uuid current-block)
215215
:sibling? true
216+
:outliner-op :paste
216217
:replace-empty-target? true
217218
:other-attrs {:block/link (:db/id (db/entity [:block/uuid block-id]))}})
218219
(state/clear-edit!)))))

0 commit comments

Comments
 (0)