From 4cc41d50fb06f8d106592db4c8aa39e20a1b668f Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 28 Nov 2026 08:11:52 +0700 Subject: [PATCH] M12: a mind map node dropped on another node becomes its child, with everything under it (#2226) --- crates/engine/src/board_mindmap_tests.rs | 39 +++++++++++++++++ crates/engine/src/boards/board/mindmap.rs | 52 +++++++++++++++++++++-- docs/boards-parity.md | 5 ++- 3 files changed, 91 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/board_mindmap_tests.rs b/crates/engine/src/board_mindmap_tests.rs index 4eee21b71..c83fddc22 100644 --- a/crates/engine/src/board_mindmap_tests.rs +++ b/crates/engine/src/board_mindmap_tests.rs @@ -211,6 +211,45 @@ fn the_first_node_carries_the_map_and_a_child_moved_by_hand_goes_back_or_swaps() assert!(same(bx(&s, kids3[1]).center().y, bx(&s, root).center().y - 72.0)); } +/// Move `n` so its middle lands on `onto`'s middle. +fn drop_on(s: &mut Session, n: NodeId, onto: NodeId) { + let d = bx(s, onto).center() - bx(s, n).center(); + s.execute("transform.move", &json!({"ids": [n], "dx": d.x, "dy": d.y})).unwrap(); +} + +#[test] +fn a_node_dropped_on_another_node_becomes_its_child_with_its_own() { + // "Dropping a node on another node makes it that node's child, with its subtree." + let mut s = board(); + let (root, [a, b, c], _) = map(&mut s); + let grandchild = id(&s.execute("board.mindMapAdd", &json!({"id": c})).unwrap(), "id"); + let depth = s.undo_depth().0; + drop_on(&mut s, c, a); + assert_eq!(arrives_from(&s, c), Some(a), "c hangs from a now"); + assert_eq!(arrives_from(&s, grandchild), Some(c), "and keeps its own child"); + assert_eq!(kids(s.doc().unwrap(), root), [a, b]); + assert!(bx(&s, c).x0 > bx(&s, a).x1 && same(bx(&s, c).center().y, bx(&s, a).center().y), "laid out in a's column: {:?}", bx(&s, c)); + assert!(bx(&s, grandchild).x0 > bx(&s, c).x1, "its child follows it"); + let line = s.doc().unwrap().nodes().find(|l| matches!(&l.board, Some(BoardItem::Connector(k)) if k.branch && k.to.node() == Some(c))).unwrap().id; + assert!(near(drawn(&s, line)[0], Point::new(bx(&s, a).x1 + END_GAP, bx(&s, a).center().y)), "the branch leaves a"); + assert_eq!(s.undo_depth().0, depth + 1, "one undo step"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(arrives_from(&s, c), Some(root)); + assert_eq!(kids(s.doc().unwrap(), root), [a, b, c]); + + // A drop on a node under the moved one, or on its own parent, changes nothing. + let was = places(&s, &[a, b, c, grandchild]); + drop_on(&mut s, c, grandchild); + assert_eq!(arrives_from(&s, c), Some(root)); + assert_eq!(places(&s, &[a, b, c, grandchild]), was, "it goes back"); + drop_on(&mut s, c, root); + assert_eq!(arrives_from(&s, c), Some(root)); + // The first node has no branch to move: it carries its map instead. + drop_on(&mut s, root, b); + assert_eq!(arrives_from(&s, root), None); + second_pass_is_a_no_op(&s); +} + #[test] fn a_deleted_node_leaves_its_children_in_place_and_takes_its_branches() { let mut s = board(); diff --git a/crates/engine/src/boards/board/mindmap.rs b/crates/engine/src/boards/board/mindmap.rs index 33ec4e08b..20d572981 100644 --- a/crates/engine/src/boards/board/mindmap.rs +++ b/crates/engine/src/boards/board/mindmap.rs @@ -323,6 +323,50 @@ fn prune_branches(doc: &mut Document, before: &Document, touched: &BTreeSet bool { + let mut at = node; + for _ in 0..=bs.len() { + let Some(b) = arriving(bs, at) else { return false }; + if b.parent == top { + return true; + } + at = b.parent; + } + true +} + +/// A node that moved by itself (a drag, a nudge) and whose middle is now on another node becomes +/// that node's child, with everything under it: its branch leaves the new parent ("Dropping a node +/// on another node makes it that node's child"). A first node, with no branch arriving, and a +/// drop on a node under the moved one change nothing. The layers whose places follow are stirred. +fn regraft(doc: &mut Document, before: &Document, touched: &BTreeSet) -> BTreeSet { + let mut stirred = BTreeSet::new(); + let is_node = |doc: &Document, id: NodeId| doc.node(id).is_some_and(|n| n.board == Some(BoardItem::MindNode)); + for &id in touched { + let moved = is_node(doc, id) && before.node(id).zip(doc.node(id)).is_some_and(|(b, n)| b.transform != n.transform); + let Some(mid) = doc.world_bounds(id).map(|r| r.center()).filter(|_| moved) else { continue }; + let bs = branches(doc); + let Some(a) = arriving(&bs, id) else { continue }; + let page = doc.page_of(id); + let onto = doc + .nodes() + .map(|n| n.id) + .filter(|t| *t != id && is_node(doc, *t) && doc.page_of(*t) == page && doc.world_bounds(*t).is_some_and(|r| r.contains(mid))) + .find(|t| !hangs_under(&bs, *t, id)); + let Some(onto) = onto.filter(|t| *t != a.parent) else { continue }; + let left = map_side(&bs, onto); + let (out, back) = if left { (Side::Left, Side::Right) } else { (Side::Right, Side::Left) }; + if let Some(BoardItem::Connector(c)) = doc.node_mut(a.line).and_then(|n| n.board.as_mut()) { + c.from = End::Node { node: onto, side: out, at: None }; + c.to = End::Node { node: id, side: back, at: None }; + stirred.extend([a.parent, onto, id]); + } + } + stirred +} + /// The boxes of the map under `root`, breadth first (so a parent always comes before its /// children), and the connectors that hold it together. `None`: a box is missing, or the map has /// more than [`MIND_MAX_NODES`] nodes (it is left as it is). @@ -366,8 +410,9 @@ fn shift(doc: &mut Document, id: NodeId, d: Point) { /// After layout and before connectors follow: the maps an edit touched are laid out again from /// their first nodes (a map that is already in place is not written to, so the pass is idempotent). -/// A branch that no longer joins two layers of its page is removed first: the only structural -/// write, and what makes a deleted node's children float free and a detached node stay detached. +/// A branch that no longer joins two layers of its page is removed first, which makes a deleted +/// node's children float free and a detached node stay detached; then a node dropped on another +/// node hangs from it ([`regraft`]). Those are the only structural writes. pub(crate) fn settle_mind_maps(doc: &mut Document, before: &Document, touched: &BTreeSet) { if !is_board(doc) || touched.is_empty() { return; @@ -376,7 +421,8 @@ pub(crate) fn settle_mind_maps(doc: &mut Document, before: &Document, touched: & if !doc.nodes().any(|n| matches!(&n.board, Some(BoardItem::Connector(c)) if c.branch)) { return; } - let stirred = prune_branches(doc, before, touched); + let mut stirred = prune_branches(doc, before, touched); + stirred.extend(regraft(doc, before, touched)); let bs = branches(doc); if bs.is_empty() { return; diff --git a/docs/boards-parity.md b/docs/boards-parity.md index ef0a736a3..6933550e0 100644 --- a/docs/boards-parity.md +++ b/docs/boards-parity.md @@ -1,6 +1,6 @@ # Boards parity -> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-27 · **Change:** minor (the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) +> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-28 · **Change:** minor (a mind map node dropped on another node becomes its child, with everything under it (#2226); the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) **Breadth ~48%, ready ~30% (estimated, erring low).** A board is a FigCraft file of its own kind (`file.newBoard`) with a dot grid on the page, sticky notes, shapes with text, connectors that @@ -57,7 +57,7 @@ all end with the same geometry. | Board widgets | missing | design-file widgets exist (`crates/engine/src/extensions/widgets.rs`), not wired to boards | | Templates (retrospective, brainstorm, flow chart…) | partial | five built-in templates drawn up for FigCraft (retrospective, brainstorm, weekly planner, flow chart, kanban board), placed from the toolbar's templates picker (each with a picture of itself) or `board.template {name, x?, y?}` as ordinary sections, stickies, shapes, connectors and text in one undo step; `board.templates` lists them. No community templates, no saving your own | | Tables | partial | `board.table {rows, columns, cells?, x?, y?}` (at most 50 × 20): an auto layout frame of rows of cells with text, a tinted header row and lines between rows and columns; a cell's row grows with its text; resizing a table by its bottom edge or its height grows the last row and a corner drag shares the change equally over every row and column (a side drag changes no row), the table keeps hugging its rows and a cell keeps at least 40 each way (measured in FigJam's web app, 2026-11-09: its floor is about 52, FigCraft's is 40, and its right edge grows only the last column); a double-click types in the cell under the pointer; add or remove a row or column from the bar over the selection or `board.tableEdit {id, action, index?}`; cells copied from a spreadsheet (tab-separated text, quoted cells kept whole) paste as a table, up to 50 × 20 with a note when there was more; undoable and synced in live sessions. No per-column widths yet (a width change splits equally), no column resizing by dragging, no cell colours, no Tab between cells; comma-separated text pastes as text | -| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). No "+" handles, outline around the map, dragging a node onto another, left side or `.jam` import yet | +| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a node dropped on another node (its middle let go on it, by a drag or a nudge) becomes that node's child with everything under it, its branch leaving the new parent, and a drop on a node under it changes nothing, nor its parent (on its own parent it lands among its siblings by its middle, as any child moved by hand does); a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). No "+" handles, outline around the map, detaching a node by dragging it away, left side or `.jam` import yet | | Code blocks | partial | from commands only so far (#2237): `board.codeBlock {x?, y?, language?, text?, width?}` places a dark panel holding monospace text (Liberation Mono 16 on a 24 line where it is embedded or installed), 576 wide; its height is its lines (32 + 24 a line, wrapped lines counted, never under four lines) and only its width can be changed (210 at least); `board.setLanguage {id?, language}` keeps one of 16 languages (TypeScript by default); `board.nextSticky` on a block makes the next one 128 to its right, as wide and in the same language. In a block Tab types two spaces, Enter keeps the line's indent, and lists, links and styled ranges don't apply. No toolbar entry, language menu, highlighting colours, line numbers or `.jam` import yet | | Washi tape, image cropping on boards | missing | images can be placed as in design files | | Audio and huddles | missing | | @@ -69,6 +69,7 @@ all end with the same geometry. | Date | Change | Summary | |---|---|---| +| 2026-11-28 | patch | M12, #2226 (part of step 3): a mind map node dragged onto another node went back to its place, so the only way to give it another parent was to delete it and add it again. The normalize pass now hangs a node that moved by itself and whose middle is on another node of the page from that node, with everything under it: its branch leaves the new parent, on that node's side, and the map lays itself out again. The first node (which has no branch) carries its map as before, and a drop on a node under the moved one changes nothing; dropped on its own parent it keeps it, taking its place among its siblings by its middle as any child moved by hand does. It works the same for a drag, a nudge, `transform.move` and a live session's edit. Detaching a node by dragging it away is not in this change: a child moved by hand still goes back or swaps with a sibling. Test: `board_mindmap_tests::a_node_dropped_on_another_node_becomes_its_child_with_its_own`. | | 2026-11-27 | minor | M12, #2395: the Marker, Highlighter and Pencil had no way to choose the ink before drawing; only a stroke already drawn could be recoloured. While one of them is the tool, a bar above the bottom toolbar shows its ink: eight colours (the Pencil also its automatic black, or white on a dark page or frame), any colour through the colour picker, and the stroke weight. Each tool keeps its own for the session and new strokes, and their preview, take it. The engine command `tool.ink {tool?, color?, weight?}` sets and reads it, and `board.ink` takes a `weight`. Tests: `new_strokes_take_the_ink_chosen_before_drawing`. | | 2026-11-11 | minor | M12, #2237 (step 1 of 4): code blocks in the document and engine. A code block is a board object of its own (`BoardItem::CodeBlock { language }`): a hugging frame holding one monospace text, 576 wide, 32 + 24 a visual line tall and never under four lines; only its width is kept from a resize. `board.codeBlock` places one, `board.setLanguage` picks one of 16 languages, and `board.nextSticky` makes the next block beside it. The normalize pass keeps a block's text plain code (`board::settle_code`) and the text editor types literally in it (two spaces for Tab, the line's indent after Enter, no list from `- `). The colours are FigCraft's own (the board's ink and tints); the sizes are from a FigJam measurement. Tests: `board_code_tests` in doc (four) and engine (thirteen). Numbers unchanged (no toolbar entry yet). | | 2026-11-10 | minor | M12, #2226 (step 2 of 4): mind maps in the UI. The Shapes flyout ends in a mind map tool (`tool.mindMap`): a click places a map with the first node's text starting there and types in it. Cmd/Ctrl+Enter adds a child of the selected or edited node (`board.mindMapAdd`), Shift+Cmd/Ctrl+Enter its next sibling (`board.nextSticky` on a node), both typing on; Tab and Shift+Tab walk a node's siblings in the map's order (`select.next`, `select.previous`). The bar over the selection colours a node's text (`board.setColor`) and shows a branch the connector's controls without the line types. Tests: `board_mindmap_tests` (four more), `board_ui_tests` (five more). Breadth ~47% → ~48%, ready ~29% → ~30%. |