Repository navigation
A port order the diagram draws is kept with its layout - #236
Merged
Merged
Conversation
The order a Free Ports layout or an applied untangle gives a definition's ports is saved in the layout file (file-level `portOrders`, by definition key) at every layout save, derived from the drawing, and the model is built in it. Every writer of the file carries the record over. A rebuild keeps the order drawn now (an undo is not saved). Layout Diagram and Untangled keep the drawn order instead of restoring the source's, so the declared-row stamp and its restore are gone: the source's order is the order of a node's children. An open bus is one place in an order and moves with its members; a cell drawn as its symbol is not reordered. An untangle applied to source keeps no layout order for what it wrote, and each try starts from the drawing the untangle began on. Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
Untangled (`dialogram.portOrder: declared`) draws every reorderable node in its source order again, the way back from a Free Ports layout after a reload, and the save lets the kept orders go; every other layout keeps the drawn order. A view that leaves its fallback's layout saves the port orders it was drawn in with the routes. A definition whose instances declare their ports in two orders is not kept. A failed untangle try shows the drawing it was reset to. The view-options doc is back on its method. Claude-Session: https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu
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.
First of the two PRs that let every Dialogram product reorder ports (plan approved 2026-11-24). This one makes a port order survive: until now nothing kept one, so a Free Ports layout was lost on reload, its routes jogging back to the declared rows.
What changes
LayoutFileContent.portOrders: one record for the file,{ [definitionKey]: { west?, east? } }, keyed bydefinitionKeyOf(name, defining file, port names), so adding or renaming a port lets the source's order stand on its own. Every writer carries it over (writeLayout,savePortBuses,saveUnwrittenStates,saveViewOptions);loadPortOrdersreads it.persistLayoutandsaveLayoutGeometrypasskeptPortOrderChanges(root): each definition whose instances are drawn in one order is kept when that is not the source's and let go when it is; definitions not drawn here, or drawn in two orders, are left as the file has them.finishLoadFromDocapplies the kept orders right afterconvertToGModelRoot(applyKeptPortOrders): the instances' ports take the rows their side already has, in the kept order. A view drawn from its fallback's layout takes the fallback's orders; a rebuild "as drawn now" (a bus or node toggle) keeps the order drawn now, since an undo is not saved.sidesOf(node, 'source')reads it there. Thewf:declaredRowYstamp andrestoreDeclaredRowsare gone. Layout Diagram, and every layout but Untangled and Free Ports, now keeps the ports in the order they are drawn in, so the order outlives the layout run after an edit. Untangled puts them back in the source's order (drawInSourceOrder), as before: the way back after a reload, and its save lets the kept orders go.regridPortRowsmoves the bus with its members under it. This also stops Free Ports from pulling a member out of its bus.wf:symbol) is not reordered, by Free Ports or a kept order: its pins are where the symbol has them (a mux's select, a register's clock).withOrdersInSource), so a later hand edit of the source's order is drawn in this diagram; undo saves the drawing before with its orders. Each try starts from the drawing the untangle began on (the probe's result depends on the order it starts from); a try that fails shows that drawing.declaredreads the source's order.Tests
kept-port-order.test.ts: applied on every instance on the same rows; a stale or partial order ignored; changes derived (kept, let go, left alone); open and closed bus share a key and an order, members move with their bus; symbols untouched; file record parsing.layout-port-orders.test.ts: set and let go by saves, survives a move (immediate and debounced), view options, buses and unwritten states; none with persistence off.kept-port-order-load.test.ts: the storage draws the kept order at load; a rebuild keeps the order drawn now.elk-layout-port-order.test.ts: Free Ports, then the orders saved, then the model built again from source: the same rows; a plain layout after keeps them; Untangled after Free Ports puts every port back on its declared row.untangle.test.ts: Apply keeps the order it does not write and lets go of the one it writes; undo saves the orders before.untangle-mcp-tools.test.ts: each try starts from the first drawing.variant-node-create-wizardtimeouts on this machine (20 s a test here, 79 ms on CI for main 5d2e73a; untouched by this change).Review (
/code-review medium)persisted-edge-routes.ts), so the other view shows routes shaped for other rows until its next layout, as any port move does today.setempty).placeNewNodespasseskeptPortOrderChanges(root)with the routes when it leaves the fallback (test ingrowth-on-submit).nodes[0]only. Fixed: a definition whose instances declare their ports in two orders (two definitions taken for one: one name, the same ports, no file) is left as the file has it. Children are in declaration order by construction (graph-gmodel-source.ts: rows are the children's indices).loadViewOptionslanded onloadPortOrders. Fixed.Next
PR 2: the untangle tools and Apply move into diagram-server, the source write becomes a hook the sidecar binds, and
/untangleis offered by every product with the diagram chat; orders that cannot go to source are kept here.https://claude.ai/code/session_011UYzzUKxNqKPdmLsRmJ6Xu