fix: paste existing asset blocks on DB graphs - #13177
Open
tiensonqin wants to merge 4 commits into
Open
Conversation
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>
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>
Contributor
There was a problem hiding this comment.
🟡 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-blocksso:pasteof 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/linkblocks. - 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-blocksdropped everyldb/asset?block whenoutliner-opwas: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-assetshook is computed on retract but is not currently applied to delete files, so the disappearing source on cut is the hard[:db/retractEntity]fromdelete-blocks, not file cleanup.Fix
:pastewithoutkeep-uuid?): insert a:block/linkembed of the original asset instead of dropping it or cloning a new file-backed identity.:pastewithkeep-uuid?): reinsert the same UUID-backed asset after the source retract, so the existing file still matches.insert-template?): keep skipping assets; they still cannot clone uuid-named files.insert-blocks: unchanged, so the asset-upload path is preserved.Tests
Added outliner unit tests in
deps/outliner/test/logseq/outliner/core_test.cljsfor copy-embed, multi-asset copy, cut-reinsert, template skip, and regular asset insert.pnpm testindeps/outliner: 105 tests, 371 assertions, 0 failures.Fixes logseq/db-test#1155