Skip to content

fix(board): place applied mindmaps beneath existing board content - #248

Merged
winlp4ever merged 2 commits into
mainfrom
fix/mindmap-apply-below-existing
Aug 24, 2026
Merged

fix(board): place applied mindmaps beneath existing board content#248
winlp4ever merged 2 commits into
mainfrom
fix/mindmap-apply-below-existing

Conversation

@winlp4ever

Copy link
Copy Markdown
Contributor

Problem

Nodes created by drawify, and by mapify / schemify / quizify / summify on synced boards, were placed on top of existing board content instead of beneath it.

Root cause: those actions go through storeMindMapuseMindMapStore → the useHarnessApplyMindMap drain, which wrote the positions from autoLayout verbatim onto the canvas. autoLayout only receives the newly-created nodes, so it lays them out anchored near the origin (0,0) with no knowledge of what's already on the board → overlap.

The local-transform path (arrangeCreatedNodes) already did the right thing — it translates the new cluster below existing content — so the two paths had diverged. (Single write_note results were never affected: write_note places them at beneathBorderOrigin itself.)

Fix — unify both paths

Extract the placement rule into two small pure helpers in beneath-border.ts:

  • originBeneath(nodes) — top-left origin just beneath a set of nodes (min x, max bottom + NOTE_TAIL_GAP); the shared rule, also now the basis of beneathBorderOrigin.
  • offsetToOrigin(cluster, origin) — the (dx, dy) that moves a laid-out cluster's top-left corner onto origin.

Then:

  • useHarnessApplyMindMap (the drain): compute the origin from existing board nodes and translate each staged cluster beneath it before applying — left-aligned, one gap below the lowest existing bottom. Multiple clusters drained together stack (each below the previous).
  • arrangeCreatedNodes: refactored onto the same helpers (behavior unchanged).

Result

Both placement paths now follow the identical "beneath existing content, left-aligned" rule that write_note uses. New drawify/mindmap output lands below your current cluster instead of overlapping it.

Tests

beneath-border.test.ts: added coverage for originBeneath (empty → (0,0); min-x / max-bottom+gap) and offsetToOrigin (empty no-op; corner-onto-origin; composed with originBeneath to prove a cluster sits one gap below existing content). Existing arrange-created-nodes tests still pass (behavior preserved). check-all clean.

The mindmap-apply drain (drawify, and mapify/schemify/etc. on synced
boards) wrote autoLayout's origin-anchored coordinates straight onto the
canvas, so new clusters landed on top of existing nodes. autoLayout only
sees the new nodes, so it can't account for what's already on the board.

Unify both placement paths on a shared rule (originBeneath + offsetToOrigin
in beneath-border): the drain now translates each staged cluster to sit
below existing content (and below any cluster already placed this drain),
left-aligned — matching write_note + arrangeCreatedNodes. arrangeCreatedNodes
is refactored onto the same helpers.
Address review findings on the placement fix:
- Gate useHarnessApplyMindMap's drain on the board's `ready` flag. A drain
  racing hydration would compute originBeneath over an empty store ({0,0})
  and place the cluster at the origin, only to be overlapped by nodes that
  hydrate a moment later. When ready flips true the effect re-runs and
  drains anything staged meanwhile.
- Compute originBeneath's min-x / max-bottom with a reduce instead of
  Math.min/max argument spread — it now runs over the whole board (the
  shared placement path), which could exceed the engine's argument limit
  when spread on a very large board.
@winlp4ever
winlp4ever merged commit d8fcafd into main Aug 24, 2026
5 checks passed
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.

1 participant