Skip to content

fix: paste existing asset blocks on DB graphs - #13177

Open
tiensonqin wants to merge 4 commits into
masterfrom
logseq/fix-paste-asset-block-2154
Open

fix: paste existing asset blocks on DB graphs#13177
tiensonqin wants to merge 4 commits into
masterfrom
logseq/fix-paste-asset-block-2154

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Fixes copy/cut + paste of imported PDF/asset blocks on DB graphs, which previously produced a blank node (and on cut also removed the source asset).

Problem

On a DB graph, selecting an imported PDF (asset block), copying or cutting it, then pasting on another page inserted nothing useful. Cut also retracted the source entity, so the PDF disappeared from the original page.

Root cause: logseq.outliner.core/insert-blocks dropped every ldb/asset? block when outliner-op was :paste (added for #572 query-paste / template work). Asset files are keyed by block UUID ({uuid}.{ext}), so a naive clone would also point at a missing file.

The worker deleted-assets hook is computed on retract but is not currently applied to delete files, so the disappearing source on cut is the hard [:db/retractEntity] from delete-blocks, not file cleanup.

Fix

  • Copy (:paste without keep-uuid?): insert a :block/link embed of the original asset instead of dropping it or cloning a new file-backed identity.
  • Cut (:paste with keep-uuid?): reinsert the same UUID-backed asset after the source retract, so the existing file still matches.
  • Templates (insert-template?): keep skipping assets; they still cannot clone uuid-named files.
  • Upload / insert-blocks: unchanged, so the asset-upload path is preserved.

Tests

Added outliner unit tests in deps/outliner/test/logseq/outliner/core_test.cljs for copy-embed, multi-asset copy, cut-reinsert, template skip, and regular asset insert.

pnpm test in deps/outliner: 105 tests, 371 assertions, 0 failures.

Fixes logseq/db-test#1155

Open in Web Open in Cursor 

Copy/paste of an imported PDF was dropping the asset in insert-blocks,
leaving a blank node. Cut then hard-retracted the source, so the PDF
disappeared. Keep uuid-preserving cut inserts, embed the original asset
on copy, and still skip assets when applying templates.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Copilot AI lite review requested due to automatic review settings September 6, 2026 16:21
Preserve each source asset uuid on the paste-link block so insert-blocks
can assign unique replacements. Also cover multi-asset copy and fix a
test paren mismatch.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new asset-to-link paste transform drops identity fields needed to preserve subtree parent mappings, which can break paste for asset blocks that have child blocks.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes copy/cut + paste behavior for existing file-backed asset blocks (e.g., imported PDFs) on DB graphs by ensuring paste no longer drops assets (or retracts them on cut) and by adding regression tests around the updated insert-blocks logic.

Changes:

  • Add special handling in logseq.outliner.core/insert-blocks so :paste of an existing asset embeds/reinserts correctly, while template insertion still skips assets.
  • Introduce helper functions to resolve existing asset entities and convert asset clipboard blocks into paste-safe :block/link blocks.
  • Add outliner unit tests covering asset paste scenarios (copy embed, cut reinsert, template skip, and non-paste insert behavior).
File summaries
File Description
deps/outliner/src/logseq/outliner/core.cljs Adjust insert-blocks preprocessing for :paste to handle existing asset blocks via linking rather than dropping/cloning.
deps/outliner/test/logseq/outliner/core_test.cljs Add unit tests for copy/cut paste behavior of asset blocks and template insertion behavior.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +808 to +812
(cond-> {:block/link asset-id
:block/title (or (:block/title block) "")}
(:block/parent block) (assoc :block/parent (:block/parent block))
(:block/level block) (assoc :block/level (:block/level block))
(:block/order block) (assoc :block/order (:block/order block)))
Reject missing sources and ancestor embeds before generating transactions.
Preserve source IDs for parent remapping and simplify asset conversion.
Add regression coverage for the three failure cases.
@tiensonqin tiensonqin self-assigned this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File vanished during cut/copy and paste

3 participants