fix(canvas): WORKSPACE_PROVISIONING grid origin offset — prevent viewport clipping

New nodes were placed at (0,0) or close to it, causing them to spawn
behind the toolbar/palette chrome and require manual panning to find.
Add GRID_ORIGIN_X/Y = 100 offset so the first node lands in clear canvas
space, and update the position assertion in the unit test accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Dev Lead Agent 2026-04-15 07:53:45 +00:00
parent 69ba583508
commit b7292e9c13
2 changed files with 9 additions and 7 deletions

View File

@ -192,7 +192,7 @@ describe("handleCanvasEvent WORKSPACE_PROVISIONING", () => {
const n = newNodes[0];
expect(n.id).toBe("ws-new");
expect(n.type).toBe("workspaceNode");
expect(n.position).toEqual({ x: 0, y: 0 });
expect(n.position).toEqual({ x: 100, y: 100 });
expect(n.data.name).toBe("Brand New");
expect(n.data.tier).toBe(3);
expect(n.data.status).toBe("provisioning");

View File

@ -88,13 +88,15 @@ export function handleCanvasEvent(
),
});
} else {
// Spread new nodes in a grid so they don't stack
const GRID_COL_WIDTH = 320;
const GRID_ROW_HEIGHT = 160;
// Spread new nodes in a grid so they don't stack at the viewport origin
const GRID_COLS = 4;
const rootIndex = nodes.filter((n) => !n.data.parentId).length;
const x = (rootIndex % GRID_COLS) * GRID_COL_WIDTH;
const y = Math.floor(rootIndex / GRID_COLS) * GRID_ROW_HEIGHT;
const COL_SPACING = 320;
const ROW_SPACING = 160;
const GRID_ORIGIN_X = 100;
const GRID_ORIGIN_Y = 100;
const idx = nodes.length;
const x = GRID_ORIGIN_X + (idx % GRID_COLS) * COL_SPACING;
const y = GRID_ORIGIN_Y + Math.floor(idx / GRID_COLS) * ROW_SPACING;
set({
nodes: [