Repository navigation
fix(outliner): move up/down takes its target in page order, not click order - #13607
Conversation
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| top-level-blocks (if (and (> (count top-level-blocks) 1) | ||
| (apply = (map #(:db/id (:block/page %)) top-level-blocks))) | ||
| (ldb/sort-page-random-blocks db top-level-blocks) |
There was a problem hiding this comment.
🟡 Selected nested pages cannot move together
Selecting two nested pages makes move-blocks-up-down sort them as blocks on one page because both lack :block/page. sort-page-random-blocks drops both pages, so moving them up or down does nothing.
Learn more
Nested pages are movable outline nodes, but page entities have no :block/page. The new equality check treats two missing page IDs as a common page. sort-page-random-blocks retains only nodes reachable through their :block/page parent path, so it returns an empty sequence for pages. The up and down branches then have no selected node to move.
Example: Place pages Alpha and Beta under Projects, alongside page Gamma. Select Alpha and Beta and press Move Down. Both page IDs are absent, the sort discards both pages, and their positions remain unchanged instead of moving past Gamma.
Recommended fix: Sort page entities by their actual outline parent/order paths rather than their missing :block/page; keep them in the selection. Add a test using two nested pages for both directions and both click orders.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (apply = (map #(:db/id (:block/page %)) top-level-blocks))) | ||
| (ldb/sort-page-random-blocks db top-level-blocks) | ||
| top-level-blocks) |
There was a problem hiding this comment.
🟡 Mixed page selections retain click order
Selecting a nested page and its ordinary sibling skips sort-page-random-blocks because their :block/page values differ. Reverse click order can still choose a selected sibling as the move target, leaving the selection unmoved.
Learn more
A nested page has no :block/page, while its ordinary sibling stores the containing page there. This guard compares page IDs rather than the outline positions of the selected siblings. When the IDs differ, it keeps click order; the neighboring target can then be part of the selection, which move-blocks refuses to move.
Example: Under Projects, arrange block A, nested page B, block C. Click B then A and press Move Up. A is chosen first, but its left sibling B is also selected; the move is rejected instead of placing A and B before their prior neighbor when one exists.
Recommended fix: Derive ordering from the actual outline tree for mixed page/block selections as well as ordinary blocks. Test a nested page and an ordinary sibling selected in reverse order with an unselected neighbor before and after them.
Was this helpful? React with 👍 or 👎 to provide feedback.
…he fork carries logseq#13607 The cherry-pick of logseq#13607 committed the test file with its conflict markers; this keeps both test sets.
…he fork carries logseq#13607 The cherry-pick of logseq#13607 committed the test file with its conflict markers; this keeps both test sets.
|
E2E verification on the real web client (DB graph, ✅ Original bug fixed: bottom-first Ctrl+click selection of two blocks now moves together (Up → ❌ Still broken — a nested page + block pair never moves as a unit: only the block relocates on each press while the page stays behind. Reproduced with Ctrl+click and Shift+click range selections, both directions, no console errors. Root cause (reproduced in the cljs suite with real Why Separately observed (pre-existing, not this diff): |
… order move-blocks-up-down takes the target of a move up from the selection's first block and of a move down from its last. The selection comes in click order: Ctrl+click c, then b, gives c, b, so a move up took c's previous sibling (b, inside the selection) and nothing moved; a move down took b's next sibling (c) (db-test logseq#1316). The selection's top-level blocks on 1 page are now put in page order first; the down branch moves those, not the raw selection.
…rder A property test: a run of 1-3 siblings, selected in a random order, is moved up or down; every block is kept, the run stays together and in order, it moves past exactly its neighbour when it has one, and at most 1 level otherwise. On master it fails 16 times in 160 moves (a run selected bottom first moves nothing); with this change it passes.
…e order Nested pages have no :block/page; sorting them as blocks of 1 page left both out, and the move did nothing. Only blocks of 1 page that the sort can place go through it; other siblings are sorted by :block/order.
move-blocks-up-down went over the outliner's 55-line large-vars limit with the page-order sort. The sort is now page-order-top-level-blocks.
2e35247 to
135da3e
Compare
sort-non-consecutive-blocks grouped blocks by :block/page and ran sort-page-random-blocks per group. Entities without :block/page (real pages, e.g. nested pages) landed in the nil group, produced no block-order-path, and were silently dropped from the moved list — a mixed page+block selection moved only the block. Replace the group-by with a root-anchored :block/order path so pages sort alongside ordinary blocks in outline position. Also give the nested-pages click-order test real :logseq.class/Page tags so its synthetic pages are actual pages — untagged entities get stamped with :block/page on move, masking the drop path.
|
E2E verification of commit ✅ The page+block mixed-move bug from my earlier comment is fixed — a nested page + block pair now moves together up and down, via both Ctrl+click and Shift+click range selections, keeping page order (not click order). All checks
The new commit replaces the |
… order Port of upstream 3ea5b19 (PR #13607) to the OCaml worker: - page-order-top-level-blocks puts a selection's top-level blocks on one page in page order before the move; the down branch moves those. - sort-non-consecutive-blocks replaces the :block/page grouping (which silently dropped entities without :block/page, e.g. nested pages) with a root-anchored :block/order path via outline-order-path. - Ports the two deterministic core_test cases (test-move-blocks-up-down-click-order, test-move-nested-pages-up-down-click-order); the long-running random property test stays cljs-only.
Fixes logseq/db-test#1316.
On a page with blocks a, b, c, d: click into c, Ctrl+click b, press Alt+Shift+Up. Nothing moves. Selected top first (b, then Ctrl+click c) the same 2 blocks move up as expected.
move-blocks-up-downindeps/outliner/src/logseq/outliner/core.cljstakes the target of a move up from the selection's first block and the target of a move down from its last. The selection comes in click order, so with c clicked first the move up takes c's previous sibling, b, which is inside the selection, andmove-blocksmoves nothing; the move down does the same with b's next sibling, c.The selection's top-level blocks, when they are on 1 page, are now put in page order before the target is taken (
ldb/sort-page-random-blocks, as the non-consecutive move already does), and the down branch moves those blocks rather than the raw selection. From review, a third commit: nested pages have no:block/page, and the page-order sort leaves out blocks it cannot place (pages, property values), so 2 nested pages selected together moved nothing. The sort now gets only blocks of 1 page with no property value among them; siblings otherwise (nested pages, or a nested page and a block beside it) are put in:block/order, and anything else keeps its order as before.New tests:
test-move-blocks-up-down-click-order(b, c selected in both orders, moved up and down): it fails on master for the bottom-first order and passes with the change.test-move-nested-pages-up-down-click-order: 2 nested pages, and a nested page with a block beside it, selected bottom first and moved up and down. 3 of its 4 cases fail without the third commit.random-move-up-down-keeps-blocks-and-order(^:long), a property test: a run of 1 to 3 siblings, selected in a random order, moved up or down 160 times; every block is kept, the run stays together and in order, it moves past exactly its neighbour when it has one, and at most 1 level otherwise. On master it fails 16 to 17 times per run; with the change it passes.frontend.modules.outliner.core-test(with its ^:long tests),frontend.worker.undo-redo-testandfrontend.handler.editor-testpass.