Skip to content

fix(outliner): move up/down takes its target in page order, not click order - #13607

Merged
tiensonqin merged 5 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-up-down-page-order
Oct 9, 2026
Merged

tiensonqin merged 5 commits into
logseq:masterfrom
yuxi-liu-wired:fix/move-up-down-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#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-down in deps/outliner/src/logseq/outliner/core.cljs takes 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, and move-blocks moves 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-test and frontend.handler.editor-test pass.

@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 2 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +1477 to +1479
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)

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.

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

Devin Review


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

Comment on lines +1478 to +1480
(apply = (map #(:db/id (:block/page %)) top-level-blocks)))
(ldb/sort-page-random-blocks db top-level-blocks)
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.

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

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 6, 2026
…he fork carries logseq#13607

The cherry-pick of logseq#13607 committed the test file with its conflict
markers; this keeps both test sets.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
…he fork carries logseq#13607

The cherry-pick of logseq#13607 committed the test file with its conflict
markers; this keeps both test sets.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E verification on the real web client (DB graph, Alt+Shift+Up/Down + Ctrl/Shift-click selections):

✅ Original bug fixed: bottom-first Ctrl+click selection of two blocks now moves together (Up → b,c,a,d; Down → a,d,b,c), identical to top-first. Two nested pages also move together correctly.

❌ 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. [A,B,SubA,SubB] select [B,SubA] + Down → expected [A,SubB,B,SubA], got [A,SubA,SubB,B].

Only the block moved — page left behind, both still selected

Root cause (reproduced in the cljs suite with real :logseq.class/Page-tagged pages): move-blocks treats a page+block pair as non-consecutive — consecutive-block? compares :block/page, which is nil for pages — so it goes through sort-non-consecutive-blocks (deps/outliner/src/logseq/outliner/core.cljs:1190), which groups by :block/page. Pages land in the nil group; sort-page-random-blocks computes no block-order-path for them (the nil page-id never matches the parent chain) and keep drops them — the page is silently removed from the moved list.

Why test-move-nested-pages-up-down-click-order passes anyway: the synthetic pages carry no :logseq.class/Page tag, so ldb/page? is false and move-block stamps :block/page on them after the first doseq case; with :block/page set they become "consecutive" with sibling blocks and never reach the drop path. With real tagged pages the [60 41] down case produces [60 70 41 44] instead of [70 41 60 44] — the exact client behavior.

Separately observed (pre-existing, not this diff): :selection/blocks keeps stale detached nodes after Ctrl+K page navigation — subsequent moves can silently apply on the previous page. Probably worth its own issue.

Written by Devin

… 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.
@megayu
megayu force-pushed the fix/move-up-down-page-order branch from 2e35247 to 135da3e Compare October 9, 2026 11:29
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.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E verification of commit e7e8ee2f6b on the real web client (DB graph, Alt+Shift+Up/Down):

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

Page+block pair moved up together: A, SubA, B, SubB

All checks
  • Ctrl+click bottom-first [B,SubA]: Up → [A,SubA,B,SubB], Down → restored (previously only the block moved — the page was dropped by the group-by :block/page in sort-non-consecutive-blocks)
  • Shift+click range [SubA,B]: both directions OK
  • Regression: two nested pages bottom-first move together; bottom-first block pair still moves correctly
  • No console errors or error toasts; selection highlight tracks the moved rows

The new commit replaces the group-by :block/page in sort-non-consecutive-blocks with a root-anchored :block/order path (outline-order-path), so entities without :block/page (real pages) sort alongside ordinary blocks instead of being silently dropped. test-move-nested-pages-up-down-click-order now tags its synthetic pages (and the container page) with :logseq.class/Page, so the mixed cases genuinely exercise the non-consecutive path — previously the synthetic pages were stamped with :block/page after the first case and never reached it.

Written by Devin

@tiensonqin
tiensonqin merged commit 3ea5b19 into logseq:master Oct 9, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 11, 2026
… 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.
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
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/move-up-down-page-order branch October 21, 2026 18:01
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.

Move up/down does nothing, or jumps, when blocks are Ctrl+clicked bottom first

3 participants