In a previous experiment, I added the ability to move events based on a grid, aka “snapping”.
But there were some bugs, so I revisted it again.
It turned the bugs were caused by calculating the snap value too early.
// calculating snap early
const delta = snap(last - event.pageX)
step.width = initial.width + delta
// calculating snap later
const delta = last - event.pageX
step.width = snap(initial.width + delta)
That fixed most of it.
Code
https://svelte.dev/repl/ced3d88a476b42ceac85c79999c47ad4?version=3.37.0
Demo
Notes
- What about multiple selections? maybe overkill for now.