Skip to content

feat(api): allow custom relative snap points for handles#6987

Merged
mimecuvalo merged 4 commits intotldraw:mainfrom
nehaaprasad:feat/allow-custom
Oct 30, 2025
Merged

feat(api): allow custom relative snap points for handles#6987
mimecuvalo merged 4 commits intotldraw:mainfrom
nehaaprasad:feat/allow-custom

Conversation

@nehaaprasad
Copy link
Copy Markdown
Contributor

@nehaaprasad nehaaprasad commented Oct 22, 2025

fixes: #6975

  • adds getAdjacentHandleForShiftSnapping() method to ShapeUtil to allow custom shapes to define which handle should be used as the reference point when dragging handles with shift key for angle snapping.

  • fixes janky snapping behavior in shapes like bezier curves where control points need to snap relative to specific anchor points instead of the default "next adjacent handle" logic.

Change type

  • feature

Test plan

  1. Added unit tests for custom adjacent handle snapping behavior
  2. All existing tests pass, ensuring backward compatibility
  • Unit tests
  • End to end tests

Release notes

  • Added support for custom relative snap points for handles via getAdjacentHandleForShiftSnapping and snapReferenceHandleId.

@huppy-bot huppy-bot Bot added api API change feature New feature labels Oct 22, 2025
@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 22, 2025

@naaa760 is attempting to deploy a commit to the tldraw Team on Vercel.

A member of the Team first needs to authorize it.

@huppy-bot
Copy link
Copy Markdown
Contributor

huppy-bot Bot commented Oct 22, 2025

naaa760 has signed the Contributor License Agreement. Thanks!

@kostyafarber
Copy link
Copy Markdown
Contributor

Hi! Thank you for your contribution, I'll take a look at it. In the meantime can you please comment with /huppy check cla to agree to our contributor license agreement if you are happy to do so :)

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

/huppy check cla

@kostyafarber kostyafarber requested a review from ds300 October 23, 2025 12:59
Comment thread packages/editor/src/lib/editor/shapes/ShapeUtil.ts Outdated
@ds300
Copy link
Copy Markdown
Contributor

ds300 commented Oct 23, 2025

Thanks for this! ❤️ Would it be possible to implement this as a property on the TLHandle type rather than as a separate shape util method? I think it would be a cleaner API that way, but maybe I'm missing some nuance of the problem.

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

Hello! @ds300 and @kostyafarber
fixed it, please let me know!

cursor[bot]

This comment was marked as outdated.

@ds300
Copy link
Copy Markdown
Contributor

ds300 commented Oct 24, 2025

this looks great now, thanks.

Do you mind running yarn build-api and committing the result? we'll need to do that before merging.

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

done! @ds300
image

@kostyafarber kostyafarber self-requested a review October 24, 2025 08:11
Comment thread packages/editor/src/lib/editor/shapes/ShapeUtil.ts Outdated
@kostyafarber
Copy link
Copy Markdown
Contributor

kostyafarber commented Oct 29, 2025

Hi @naaa760 sorry for the delay! If you could post a comment that says "I have read and agree to the Contributor License Agreement." and then after in a new comment write /huppy check cla.

I forgot to mention that we need that as a comment. Thank you!

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

I have read and agree to the Contributor License Agreement.

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

/huppy check cla

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
examples Ready Ready Preview Oct 30, 2025 9:48am
1 Skipped Deployment
Project Deployment Preview Updated (UTC)
tldraw-shader Ignored Ignored Preview Oct 30, 2025 9:48am

@mimecuvalo
Copy link
Copy Markdown
Member

@naaa760 I think the issue wasn't the huppy cla check. The thing that David asked above:

Do you mind running yarn build-api and committing the result? we'll need to do that before merging.

Looks like you had a comment above saying you ran it, but maybe it didn't get commited to the PR. (I'm not seeing it in the changed files). thanks!

@huppy-bot
Copy link
Copy Markdown
Contributor

huppy-bot Bot commented Oct 29, 2025

Hey! 👋

This PR contains changes to api-report.api.md, which means you've made some API changes. To help reviewers and SDK users understand the impact, please add a "### API changes" section to your PR description.

Here's an example:

### API changes
- Describe what API changes were made
- List any breaking changes
- Note any new or removed parameters

Once you add this section, the check will pass automatically!

@mimecuvalo
Copy link
Copy Markdown
Member

almost there :) last check just says a linting issue. run yarn format to fix up — sorry for all the back-n-forth!

@nehaaprasad
Copy link
Copy Markdown
Contributor Author

almost there :) last check just says a linting issue. run yarn format to fix up — sorry for all the back-n-forth!

no worries, i updated it.

@mimecuvalo
Copy link
Copy Markdown
Member

thank you!

Merged via the queue into tldraw:main with commit 878f9d8 Oct 30, 2025
11 of 18 checks passed
@steveruizok steveruizok added the sdk Affects the tldraw sdk label Jan 2, 2026
@steveruizok steveruizok changed the title feat: allow custom relative snap points for handles feat(api): allow custom relative snap points for handles Jan 2, 2026
NathanFlurry pushed a commit to rivet-dev/tldraw that referenced this pull request Jan 18, 2026
fixes: tldraw#6975

- adds `getAdjacentHandleForShiftSnapping()` method to `ShapeUtil` to
allow custom shapes to define which handle should be used as the
reference point when dragging handles with shift key for angle snapping.

- fixes janky snapping behavior in shapes like bezier curves where
control points need to snap relative to specific anchor points instead
of the default "next adjacent handle" logic.

### Change type

- [x] `feature`
- [x] `api`

### Test plan

1. Added unit tests for custom adjacent handle snapping behavior
2. All existing tests pass, ensuring backward compatibility

- [x] Unit tests

### API changes

- Added `snapReferenceHandleId?: string` property to `TLHandle`
interface
- Allows handles to specify a custom reference point for shift-modifier
angle snapping
- No breaking changes - optional property with full backward
compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API change feature New feature sdk Affects the tldraw sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow custom relative snap points for handles

5 participants