Skip to content

fix(outliner): move consecutive blocks in page order across parents - #13605

Closed
yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-keeps-page-order
Closed

yuxi-liu-wired wants to merge 2 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-keeps-page-order

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes logseq/db-test#1297.

Moving a last child together with the block after its parent can reverse the 2. On a page with a, b (children b1, b2), c: Ctrl+click b2, then c, move them into a block elsewhere, undo twice and redo twice; the target holds c, b2.

get-top-level-blocks in deps/outliner/src/logseq/outliner/core.cljs decides that a consecutive selection is reversed by comparing the :block/order of its first 2 blocks. Order values are comparable only between siblings, but a last child and the block after its parent count as consecutive too (consecutive-block?), and their values are unrelated. In the steps above b2 has "b9R" and c "b9S"; undoing the move gives c "b9Q", so the redo compares "b9R" with "b9Q" and moves c first.

When the first 2 blocks have different parents on the same page, the selection is now put in page order with ldb/sort-page-random-blocks, the function the non-consecutive case already uses. Blocks with the same parent are compared by :block/order as before. A selection holding a property value block is left unsorted, as on master: the page-order sort has no path for such a block and would leave it out of the move (a second commit, from review).

New test test-move-last-child-and-next-block-keeps-page-order: it gives the last child an order greater than the next block's and moves both; it fails on master (the target holds 5, 4) and passes with the change. test-move-property-value-and-next-block-keeps-both: a property value that is the last child, with the block after its parent; both move (the first commit alone moved only the second). frontend.modules.outliner.core-test (with its ^:long random tests), frontend.worker.undo-redo-test, frontend.worker.outliner-undo-property-test and frontend.handler.editor-test pass.


Devin Review

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +1210 to +1212
(and (not non-consecutive?) b (not same-parent?) (de/entity? a)
(= (:db/id (:block/page a)) (:db/id (:block/page b))))
(ldb/sort-page-random-blocks (.-db a) top-level-blocks)

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.

🔴 Property values disappear from consecutive selections

When a property value and its parent's next sibling are selected, get-top-level-blocks drops the property value. sort-page-random-blocks excludes property-created blocks, so moves and deletes process only the sibling.

Learn more

The page-order sorter builds a path from each block to its page. It returns no path for blocks with :logseq.property/created-from-property or :block/closed-value-property, and keep removes them from its result in block-order-path and sort-page-random-blocks. get-non-consecutive-blocks can nevertheless classify a last property child and its parent's next sibling as consecutive. The changed branch then sends both through the sorter. move-blocks and delete-blocks use its reduced selection, omitting the property child.

Example: On a page with A (whose last child is property value V) followed by B, select V and B and move them under C. The sorted selection contains B alone; V remains under A. Deleting that selection likewise leaves V behind.

Recommended fix: Do not pass property-created or closed-value blocks through sort-page-random-blocks unless it can return every selected block in the required order. Handle mixed page-order selections without dropping entries, and add move/delete tests for a last property child followed by its parent's next sibling.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
get-top-level-blocks decided a consecutive selection was reversed by
comparing the :block/order of its first 2 blocks. Order values are
comparable only between siblings, but a last child and the block after
its parent count as consecutive too; for those 2 the values are
unrelated, and a move could reverse them (db-test logseq#1297: after an undo
re-orders the second block, the redo moves it first).

When the first 2 blocks have different parents on the same page, the
selection is put in page order with ldb/sort-page-random-blocks.
The page-order sort leaves out blocks with no page-order path, so a
property value selected with its parent's next sibling dropped out of
the move or delete. Such selections keep their order unsorted.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined with the other PRs that change the same files into #13783.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/move-keeps-page-order branch October 21, 2026 18:02
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.

Moving a nested block and the block after its parent can reverse them

1 participant