Discuss Scratch

liam48D
Scratcher
1000+ posts

Block/script shared clipboard

This is a repost of my issue on GitHub: https://github.com/LLK/scratch-blocks/issues/455

One feature that would be really handy is the ability to copy and paste Scratch blocks. At the moment (Scratch 2.0), you can already do this in some ways:

  • Select “duplicate” from a block's context menu
  • Drag a block or script onto a sprite in the sprites pane
  • Use the “stamp” button in the toolbar to copy the block or script
  • Use the backpack to bring blocks or scripts from one sprite to another, even across projects and devices

The last item there is similar to what I'm suggesting - copying actual block data to the system clipboard.

It's better than using the backpack, because:

  • Systems are starting to implement *shared* clipboards, meaning the clipboard is shared across multiple devices
    - And even if you're on a device that doesn't have shared clipboards, the clipboard is generally shared among all the applications on your device, meaning you could have two browser windows open, each working on Scratch projects
  • Because of shared clipboards, you don't need to be logged into the same account as the account you copied the block from, unlike the backpack
  • It's quick - you don't need to reload the entire page to see the most recent items in the backpack (though this *should* be fixed, for what reason should you need to reload the page to see items in your backpack?)
  • Depending on how scripts are copied - I'm thinking the JSON representation of the script you'd find in an sb3 project - you could probably upload a script onto the internet, so that people can copy from your document to their project

I'm thinking it shouldn't be very difficult to implement this. Here's a quick code mockup:

// When a script, block, etc. is created:
// 'copy' is probably localized to 'Copy to clipboard'
block.contextMenu.addItem('copy', function() {
  // This function doesn't exist with this name, of course. I'm not entirely certain what
  // the exact code to copy is but it's possible and has been done on many sites
  // and web applications before.
  // Also, I don't know what the name of the function to convert a script to JSON is,
  // so I'm using "serialize" :)
  // I'm also assuming there's a "duplicate" method on blocks that behaves however
  // we want duplicating scripts to be have, (copy child blocks, blocks below, etc.)
  // Could probably name this method better but it's for the demo :)
  copyToBrowserClipboard(block.duplicate().serialize())
})

The trouble is pasting. There are a couple of ways we could do this:

  • Make a hidden input box that's always selected when you're using the workspace. Input only works via paste. Kind of a dirty hack, and you can't use a context menu -> paste method if you do it that way.
  • Show a prompt asking for the user to paste a block. I like this more.

The nice thing about using a prompt is that it can be a custom dialog - for example, before a block is *actually* pasted into the workspace, you might be able to see a picture of the block in the dialog. It can be triggered via context menu, or by listening for a Command/Control-V press.

Mockup code for prompt:

function pastePrompt() {
  const prompt = makePastePrompt()
  prompt.addEventListener('done', function() {
    workspace.addScript(prompt.value) // see below section, "things to consider"
  })
}
workspace.contextMenu.addItem('paste', pastePrompt)
workspace.addEventListener('key', function(key) {
  // isCombo is a fake function here that will check if a key press is the right character,
  // has the right modifiers (command/control), etc. for mockup
  if (isCombo(key, 'Command+V')) {
    pastePrompt()
  }
})

Things to consider:

  • Where should blocks be pasted to? Where the mouse clicked?
  • If you copy a reporter, where will it go? Can you use the paste prompt on an input?
    - What if you try to paste a stack block into an input?
  • Can you paste a script between two blocks, if it fits?
  • Would it just be better to make the block be automatically grabbed when you accept the paste, or would that be confusing or surprising?

I guess this is getting kind of long.. that's all I have for this suggestion! What should be changed? (Probably the title of this issue.. maybe it would better fit as a “design” issue.)

edit: this could probably work with sprites, as well, but I'm not sure how to save costumes or sounds - maybe as data URIs? But those have length limits..
alexphan
Scratcher
1000+ posts

Block/script shared clipboard

Semi support, you can use this, but it would be a bit more convenient this way.
Also, what would happen if you tried to paste block data into a text file? What would it look like?
liam48D
Scratcher
1000+ posts

Block/script shared clipboard

alexphan wrote:

Semi support, you can use this, but it would be a bit more convenient this way.
Is it possible to create Scratch projects using that?

alexphan wrote:

Also, what would happen if you tried to paste block data into a text file? What would it look like?
As I said in my original post – "Depending on how scripts are copied - I'm thinking the JSON representation of the script you'd find in an sb3 project - you could probably upload a script onto the internet, so that people can copy from your document to their project."
alexphan
Scratcher
1000+ posts

Block/script shared clipboard

liam48D wrote:

As I said in my original post – "Depending on how scripts are copied - I'm thinking the JSON representation of the script you'd find in an sb3 project - you could probably upload a script onto the internet, so that people can copy from your document to their project."
Oh, I see. I change to 75% support.
MathlyCat
Scratcher
1000+ posts

Block/script shared clipboard

I have a lot of good things to say. This post is one of the few suggestions that's properly structured to counter each argument made against it. I like that and now I don't have to waste my time asking questions. As for myself I would be quite happy if such were implemented.
Sheep_maker
Scratcher
1000+ posts

Block/script shared clipboard

I think pasting a reporter while typing in an input would replace the input with the reporter

Powered by DjangoBB