Skip to content

Paste block in viewport / near cursor #6848

@BeksOmega

Description

@BeksOmega

🚧⚠️🚧 This issue is being saved for Grace Hopper Open Source Day. 🚧⚠️🚧 An event we're running to help girls and non-binary technologists make their first contributions to open source! Please see our list of help wanted issues if you'd like to contribute!


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

  1. Copy a block to the clipboard using ctrl + c.
  2. Scroll the workspace so that the original block is not in view.
  3. Paste the bloc using ctrl + v.
  4. 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

  1. Follow the reproduction steps to reproduce the bug.
  2. Add a getRelativeToSurfaceXY(): Coordinate method to the IMovable interface.
  3. Modify the copy and cut callbacks to store the result of getRelativeToSurfaceXY in a copyCoords variable.
  4. Modify the paste callback to:
    A. Run copyWorkspace.getMetricsManager().getViewMetrics(true) to get the coordinates of the viewport of the workspace.
    B. If the copyCoords are within the viewport, pass copyCoords to clipboard.paste.
    C. Otherwise, paste at a new Coordinate in the middle of the viewport. You can use the view metrics to calculate this.
  5. 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.⚠️

Metadata

Metadata

Assignees

Labels

ghc-osdReserved for open source day: https://anitab-org.github.io/open-source-day/issue: bugDescribes why the code or behaviour is wrongsize: smallBugs that can be picked up and completed in 1-3 days

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions