fix(board): place applied mindmaps beneath existing board content - #248
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
storeMindMap→useMindMapStore→ theuseHarnessApplyMindMapdrain, which wrote the positions fromautoLayoutverbatim onto the canvas.autoLayoutonly 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. (Singlewrite_noteresults were never affected:write_noteplaces them atbeneathBorderOriginitself.)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 ofbeneathBorderOrigin.offsetToOrigin(cluster, origin)— the(dx, dy)that moves a laid-out cluster's top-left corner ontoorigin.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_noteuses. New drawify/mindmap output lands below your current cluster instead of overlapping it.Tests
beneath-border.test.ts: added coverage fororiginBeneath(empty → (0,0); min-x / max-bottom+gap) andoffsetToOrigin(empty no-op; corner-onto-origin; composed withoriginBeneathto prove a cluster sits one gap below existing content). Existingarrange-created-nodestests still pass (behavior preserved).check-allclean.