Repository navigation
Improve canvas connection feel: snapping, magnetic handles, duplicate guards, calmer preview - #4
Merged
Merged
Conversation
…uplicate guards Four small quality-of-life changes to how connecting and arranging feels, adapted from studying how n8n and React Flow's own examples tune their canvases: - Snap dragging to a 12px grid (half the 24px background dot gap), so nodes line up without an organize pass. - connectionRadius=60 makes handles magnetic: dropping a connection near a handle attaches it instead of silently cancelling. - Duplicate connections are refused everywhere: hasEquivalentEdge compares connections after createEdge's handle normalization, the store's addEdgeFromConnection now returns whether it added (the connect tool toasts "These nodes are already connected"), and isValidConnection gives the same feedback live during a drag. Reverse edges and first loops are still allowed; a second identical loop is not. - The drag-out connection preview waits 300ms before appearing, so an accidental press on a handle no longer flashes a stray line. The preview uses the same smooth-step styling as committed edges. Note: the two storage failure tests in store.test.ts fail on main before this change (see the separate fix PR); no new failures are introduced.
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.
What
Four small quality-of-life changes to how connecting and arranging feels on the canvas, adapted from studying how n8n and React Flow's own examples tune theirs:
Grid snapping —
snapToGridwith a 12px grid (half the 24px background dot gap), so dragged nodes line up without needing an organize pass.Magnetic handles —
connectionRadius={60}: dropping a connection near a handle attaches it instead of silently cancelling. This is the single biggest "why didn't my connection take?" fix.Duplicate-connection guard —
hasEquivalentEdge(ingraphUtils) compares connections aftercreateEdge's handle normalization. It's enforced in both paths:addEdgeFromConnectionnow returns whether it added, and the connect tool toasts "These nodes are already connected" instead of stacking an invisible second edge;isValidConnectiongives the same feedback live during a drag.Reverse edges (
b → a) and first loops are still allowed; a second identical edge/loop is not.Calmer connection preview — the drag-out line waits 300ms before appearing, so an accidental press on a handle no longer flashes a stray line. When it appears it uses the same smooth-step styling as committed edges (
var(--accent), dashed).Tests
graphUtils.test.ts: equivalence across default handles, reversed direction, distinct handle pairs, loops.store.test.ts: duplicate connect is a no-op (edge count and revision unchanged, so undo history stays clean), reverse edge and first loop still allowed.Note: the two storage-failure tests in
store.test.tsfail onmainbefore this branch — that's #3, independent of this change.