-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
🚧
Check for duplicates
- I have searched for similar issues before opening a new one.
Description
When you paste a block, you expect the block to appear in the part of the workspace you are looking at. Usually either:
- In the middle of the view
- Near where your cursor is
Currently in Blockly, this is ignored, and blocks are always pasted near the original block that was copied.
Reproduction steps
- Copy a block to the clipboard using ctrl + c.
- Scroll the workspace so that the original block is not in view.
- Paste the bloc using ctrl + v.
- Observe how the new pasted block is not in view, and was instead pasted near the original block.
Additional Info
Pasting in the viewport may cause cascading block bumps for the pasted blocks, which would also be a bad user experience. I'm nopt sure if this occures with the current system or not.
Note: block bumping is when we move blocks away from other blocks connections so they don't accidentally appear to be connected.
To Fix
- Follow the reproduction steps to reproduce the bug.
- Add a
getRelativeToSurfaceXY(): Coordinatemethod to the IMovable interface. - Modify the copy and cut callbacks to store the result of
getRelativeToSurfaceXYin acopyCoordsvariable. - Modify the paste callback to:
A. RuncopyWorkspace.getMetricsManager().getViewMetrics(true)to get the coordinates of the viewport of the workspace.
B. If thecopyCoordsare within the viewport, passcopyCoordstoclipboard.paste.
C. Otherwise, paste at a newCoordinatein the middle of the viewport. You can use the view metrics to calculate this. - Rerun the reproduction steps. This time if the original block is not in view, the block should be pasted in the middle of the viewport.
⚠️