tricker than I thought: making sure that pasted shapes don't end up on top of each other
Normally we'd like to place a pasted shape in the middle of the editor. You can think of this as an offset of [0,0] from the center.
But there are two circumstances where we'd want to offset this position. First, if the shapes that we copied happen to also be perfectly centered in the window, then we'd increase our offset (e.g. to [16, 16]).
Second, we would need to increase the offset if the viewport's center is still at the same place as the last time we pasted a shape.
Moving the viewport should reset this offset; and so should copying a new shape.
Undos will break this system though, because we aren't reversing that offset on undo. I could store the offset in our state, which would get undone... but I might leave it here for now.
Creative apps have really complicated logic around where things are pasted—some of which can be very hard to predict, especially as we get into groups! So I'm sure I'll be back to this feature again soon.
Anyway, here's what I actually sat down to implement
Later that day,
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.