Skip to content

Clear system clipboard on block copy to prevent pasting files. #10463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

microbit-matt-hillsdon
Copy link
Contributor

Copy link
Member

@riknoll riknoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the proper fix here would be to call preventDefault() on the event passed into the callback if there is a block copied rather than messing with the clipboard

@microbit-matt-hillsdon
Copy link
Contributor Author

I think the proper fix here would be to call preventDefault() on the event passed into the callback if there is a block copied rather than messing with the clipboard

I worry this would disable file paste forever once you've copied a block (as the Blockly clipboard won't clear). I'm not sure that would be OK.

It's hard to do a perfect job here with a separate clipboard. With the clearing approach it's still not great in the copy a block then copy a file case as both events will still fire. But for typical user flows of copy and then paste it should be better. What do you think?

@microbit-matt-hillsdon
Copy link
Contributor Author

Investigated further and I think there's a simpler fix. The event sequence is:

  1. keydown handled via Blockly onKeyDown (potentially pasting block)
  2. paste event handled in setupDragAndDrop

Neither code is aware of the other.

However, calling preventDefault on the key event prevents the paste event and we can do this at the point we've decided to handle the paste. So that's a simple and logical fix. I'll close this and open a new PR for that.

Should ideally also happen in Blockly and in the keyboard nav plugin if it continues to replace paste actions. I'll follow up on those.

Closing.

@microbit-matt-hillsdon microbit-matt-hillsdon deleted the system-clipboard-fix branch May 2, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy and paste block causes "Opps, don't know how to load this file!"
2 participants