You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cut and paste block breaks block references (block UUID) #4491
:type/bugSomething isn't working. Affects daily use.block-refeditor:copy-pasteClipboard data attached is appreciated. See menu - bug report - clipboard inspectorestimate: very largeA project level feature (as large as the projects listed in our roadmap)
Right click -> Cut only adds plain text to clipboard.
Reproduce the Bug
Create a block with a block reference (so that the content of the block contains something like ((a852377d-6614-48fd-8404-e7c8e25f43c3)))
Right click the bullet point -> Cut
Paste the block somewhere
The new block is the plain text content of the referenced block, not a live block reference.
Expected Behavior
I would expect the newly pasted block to contain a block reference, not the plain text content.
I would expect right click > cut to have the same behaviour as highlighting the block and pressing Ctrl-X (which does copy the block reference.)
Screenshots
No response
Desktop Platform Information
No response
Mobile Platform Information
No response
Additional Context
No response
Reacted by Tobias Domhan
Reacted by ⨏𝑒𝑙𝑖d𝑧, Junyi Du, situ2001 and Albert Riedinger
@andelf Hope fix it ASAP. When I reorganize my blocks with cut function, all the block ref loss their content. if the blocks are folded, users can not find their notes have been lost.
@tiensonqin@logseq-cldwalker
I don't know much about the mechanism to outliner core. So I am here to tell you what I tested and figured out. I hope this bug can be solved. Thanks.
This may be more tricky than my initial idea. Looking through the codebase, I have found that there is a option keep-uuid? in frontend.handler.editor/paste-block
"Given a vec of blocks, insert them into the target page.
keep-uuid?: if true, keep the uuid provided in the block structure."
[blocks {:keys [content-update-fn
exclude-properties
target-block
sibling?
keep-uuid?]
:or {exclude-properties []}}]
After I dug deep till function frontend.modules.outliner.core/insert-blocks-aux, I found that keep-uuid? will be invalid since we are pasting the blocks into an empty block. The first pasted block's uuid will be replaced by the target-block's uuid.
Digging around more on this problem it looks like the uuid is preserved correctly while the db/id is not preseved. This means all existing blocks that have mention the cut block in path-refs will point to a non-existing db/id.
When dragging/dropping the db/id is preserved correctly.
btw, by opening a block in the side bar one can drag/drop from anywhere to anywwhere as a workaround. That said, it would be great to fix the cut/paste behavior.
Before the cut+paste:
After the cut+paste (missing reference to the main block that is cut/pasted):
Note: the uuids are fine, but the path-refs of the block that points to the main block that is cut/paste point to the wrong (old) db/id.
The child of the cut+pasted block now has path-refs to both the old and the new :db/id. I guess that is why the reference is still shown (and the wrong reference to the old, non-existent block, is ignored).
I found the problem. When the data is copied the references of the root node are already missing. The culprit seems to be tree/get-sorted-block-and-children. The root-block returned by db/pull misses the :block/_refs while blocks returned by db/get-block-and-children contain :block/_refs. I know too little about the inner workings for Logseq and Datascript to know if this is expected. One workaround is to use the root-block returned by db/get-block-and-children instead of ignoring it. There may also be a way to modify db/pull isntead.
One problem that remains is that the path-refs of the existing nodes will continue to point to the old db/:id. Not sure if this is a problem in practice (other than memory if those items are not cleared in the db).
:type/bugSomething isn't working. Affects daily use.block-refeditor:copy-pasteClipboard data attached is appreciated. See menu - bug report - clipboard inspectorestimate: very largeA project level feature (as large as the projects listed in our roadmap)
Activity
XinLi0111 commentedon Oct 16, 2022
@andelf Hope fix it ASAP. When I reorganize my blocks with cut function, all the block ref loss their content. if the blocks are folded, users can not find their notes have been lost.
Windows 11, Desktop 0.8.8

situ2001 commentedon Jan 30, 2023
I have also faced the issue for a long time. I will try myself to fix it these days.
situ2001 commentedon Jan 30, 2023
@tiensonqin @logseq-cldwalker
I don't know much about the mechanism to outliner core. So I am here to tell you what I tested and figured out. I hope this bug can be solved. Thanks.
The commit that I am testing on: bcaec40
Background
This may be more tricky than my initial idea. Looking through the codebase, I have found that there is a option
keep-uuid?infrontend.handler.editor/paste-blocklogseq/src/main/frontend/handler/editor.cljs
Lines 1938 to 1946 in dd006bf
After I dug deep till function
frontend.modules.outliner.core/insert-blocks-aux, I found thatkeep-uuid?will be invalid since we are pasting the blocks into an empty block. The first pasted block's uuid will be replaced by the target-block's uuid.logseq/src/main/frontend/modules/outliner/core.cljs
Lines 385 to 387 in 904eff6
How to prove my assumption
A very simple idea, just pass
:keep-uuid trueto the options of this function call.logseq/src/main/frontend/handler/paste.cljs
Line 75 in f8ace0b
Create a page for testing like this.

Select the whole block with content

12345and click cut.Find an empty block and put the cursor in the starting position. Click

cmd+vto paste the block. You will find that the block ref is gone.And it is very easy to prove my assumption. Just paste the blocks at the end of the block. And, boom! The block uuid is kept.

Stan-RED commentedon Apr 16, 2023
The same problem. Very annoying, especially when reorganizing notes and moving block from one page to another which can't be done by dragging block.
cnrpman commentedon May 24, 2023
The tricky thing is the "pasting" with
id::can only happens once - otherwise would cause duplicated uuids.Need a good design of the clipboard metas. I would suggest doing this when having an overhaul to the copy-pasting features.
[-]Cut and paste block removes block references[/-][+]Cut and paste block breaks block references (block UUID)[/+]tdomhan commentedon Dec 7, 2023
I have the same problem unfortunately.
tdomhan commentedon Dec 7, 2023
Looks like the
idis correctly set, but the UI doesn't realize until after a reindex.tdomhan commentedon Jan 9, 2024
Digging around more on this problem it looks like the uuid is preserved correctly while the
db/idis not preseved. This means all existing blocks that have mention the cut block inpath-refswill point to a non-existingdb/id.When dragging/dropping the
db/idis preserved correctly.btw, by opening a block in the side bar one can drag/drop from anywhere to anywwhere as a workaround. That said, it would be great to fix the cut/paste behavior.
tdomhan commentedon Jan 10, 2024
Before the cut+paste:



After the cut+paste (missing reference to the main block that is cut/pasted):
Note: the uuids are fine, but the path-refs of the block that points to the main block that is cut/paste point to the wrong (old) db/id.
tdomhan commentedon Jan 10, 2024
The child of the cut+pasted block now has path-refs to both the old and the new :db/id. I guess that is why the reference is still shown (and the wrong reference to the old, non-existent block, is ignored).
tdomhan commentedon Jan 11, 2024
I found the problem. When the data is copied the references of the root node are already missing. The culprit seems to be
tree/get-sorted-block-and-children. The root-block returned bydb/pullmisses the:block/_refswhile blocks returned bydb/get-block-and-childrencontain:block/_refs. I know too little about the inner workings for Logseq and Datascript to know if this is expected. One workaround is to use the root-block returned bydb/get-block-and-childreninstead of ignoring it. There may also be a way to modifydb/pullisntead.One problem that remains is that the path-refs of the existing nodes will continue to point to the old
db/:id. Not sure if this is a problem in practice (other than memory if those items are not cleared in the db).