Skip to content

Snapping and guides in the editor - #13

Merged
freethinkel merged 2 commits into
mainfrom
fmc(snapping-guides)
Jul 28, 2026
Merged

Snapping and guides in the editor#13
freethinkel merged 2 commits into
mainfrom
fmc(snapping-guides)

Conversation

@freethinkel

Copy link
Copy Markdown
Owner

Closes #4

Drag a widget or a group on the canvas and its box now snaps to the other elements: start/centre/end of the dragged box are pulled onto the same lines of every other hitbox, plus the canvas edges and centre. The line that caught it is drawn across the canvas while the pointer is down. holds the drag off the guides.

Where things live

  • editor/lib/snap.ts — pure: snapTargets() (collect the lines, skipping the dragged subtree) and snapAxis() (nearest line within the tolerance).
  • editor/shared/constants.tsSNAP_THRESHOLD, GUIDE_WIDTH, GUIDE_COLOR.
  • pages/editor.svelte — the wiring: targets taken once on pointerdown, guides drawn after the selection box.

Thresholds are in screen pixels and converted at the use site (466 / canvas.getBoundingClientRect().width) — the canvas is drawn in 466-space but displayed much smaller, so a tolerance in canvas units shrinks to ~2 px of pointer slack and never catches.

Tests

  • tests/editor-snap.test.ts (unit) — tolerance boundary, nearest-line wins, butting a box against a neighbour's edge.
  • tests/editor-snap.browser.test.ts — the real path: mounts the editor page, drags with pointer events on the canvas, asserts the box lands flush and that the guide is actually painted.

Not included: snapping on resize or on arrow-key moves, and equal-spacing / distance guides.

🤖 Generated with Claude Code

https://claude.ai/code/session_011ZdiFtcW3mifwmYtspMcB7

freethinkel and others added 2 commits July 28, 2026 13:12
While a widget or group is dragged, its box's start/centre/end lines are
pulled onto the same lines of every other hitbox plus the canvas edges and
centre, and the line that caught it is drawn across the canvas. ⌥ holds the
drag off the guides.

Thresholds are in screen pixels and converted at the use site: the canvas is
drawn in 466-space but displayed much smaller, so a tolerance in canvas units
shrinks to about two pixels of pointer slack and never catches.

Closes #4

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZdiFtcW3mifwmYtspMcB7
Cosmetic only: prettier's 80-column default had broken up lines the repo's
oxfmt keeps on one, so `oxfmt --check` failed on files nothing had touched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011ZdiFtcW3mifwmYtspMcB7
@freethinkel
freethinkel merged commit c9747f3 into main Jul 28, 2026
@freethinkel
freethinkel deleted the fmc(snapping-guides) branch July 28, 2026 14:25
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.

Snapping and Guides in the Editor

1 participant