Skip to content

Cut and paste block breaks block references (block UUID) #4491

Closed

Description

@marcusround

What happened?

Right click -> Cut only adds plain text to clipboard.

Reproduce the Bug

  1. Create a block with a block reference (so that the content of the block contains something like ((a852377d-6614-48fd-8404-e7c8e25f43c3)))
  2. Right click the bullet point -> Cut
  3. Paste the block somewhere
  4. 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

Activity

  1. added
    editor:copy-paste
    on Mar 8, 2022
  2. XinLi0111 commented on Oct 16, 2022

    @XinLi0111

    @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
    ls_cut

  3. moved this to 🗄 Backlog in :Logseq/Issue-Trackeron Jan 1, 2023
  4. situ2001 commented on Jan 30, 2023

    @situ2001
    Contributor

    I have also faced the issue for a long time. I will try myself to fix it these days.

  5. self-assigned this
    on Jan 30, 2023
  6. added
    :type/bug
    on Jan 30, 2023
  7. removed their assignment
    on Jan 30, 2023
  8. situ2001 commented on Jan 30, 2023

    @situ2001
    Contributor

    @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? in frontend.handler.editor/paste-block

    (defn paste-blocks
    "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.

    uuids (if replace-empty-target?
    (assoc uuids (:block/uuid (first blocks)) (:block/uuid target-block))
    uuids)

    How to prove my assumption

    A very simple idea, just pass :keep-uuid true to the options of this function call.

    (editor-handler/paste-blocks blocks {})))

    Create a page for testing like this.
    image

    Select the whole block with content 12345 and click cut.
    image

    Find an empty block and put the cursor in the starting position. Click cmd+v to paste the block. You will find that the block ref is gone.
    Kapture 2023-01-30 at 19 19 24

    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.
    Kapture 2023-01-30 at 19 23 33

  9. Stan-RED commented on Apr 16, 2023

    @Stan-RED

    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.

  10. cnrpman commented on May 24, 2023

    @cnrpman
    Collaborator

    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.

  11. added
    estimate: very large
    on May 24, 2023
  12. changed the title [-]Cut and paste block removes block references[/-] [+]Cut and paste block breaks block references (block UUID)[/+] on Jun 5, 2023
  13. tdomhan commented on Dec 7, 2023

    @tdomhan
    Contributor

    I have the same problem unfortunately.

  14. tdomhan commented on Dec 7, 2023

    @tdomhan
    Contributor

    Looks like the id is correctly set, but the UI doesn't realize until after a reindex.

  15. tdomhan commented on Jan 9, 2024

    @tdomhan
    Contributor

    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.

  16. tdomhan commented on Jan 10, 2024

    @tdomhan
    Contributor

    Before the cut+paste:
    Screenshot 2024-01-10 at 06 40 53
    After the cut+paste (missing reference to the main block that is cut/pasted):
    Screenshot 2024-01-10 at 06 41 10
    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.
    Screenshot 2024-01-10 at 06 44 22

  17. tdomhan commented on Jan 10, 2024

    @tdomhan
    Contributor

    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).

    Screenshot 2024-01-10 at 07 18 58
  18. tdomhan commented on Jan 11, 2024

    @tdomhan
    Contributor

    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).

  19. moved this from 🗄 Backlog to ✔ DONE in :Logseq/Issue-Trackeron Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    :type/bugblock-refeditor:copy-pasteestimate: very large

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions