question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Block/script clipboard, shared

See original GitHub issue

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…

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:5
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
PullJoshcommented, Jun 28, 2016

I love this idea! Desmos does something similiar when copy & pasting: image Perhaps something could be learned from how it’s done there?

2reactions
luxaritascommented, Jun 28, 2016

Might it be possible to accept multiple different inputs when pasting, so scratchblocks would be available, but not required as the sole interchange format?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Block/script shared clipboard - Discuss Scratch
Systems are starting to implement *shared* clipboards, meaning the clipboard is shared across multiple devices
Read more >
Video proof for low block script: Inputs show P2 : r/Tekken
Cheating is rampant in Tekken, and there is absolutely no anti cheat. The only way to prove you are genuine is to show...
Read more >
Pipe to/from the clipboard in a Bash script - Stack Overflow
Try the Screen command readreg . Under Windows 10+ or Cygwin, use /dev/clipboard or clip . Share.
Read more >
PowerShell Remoting, Part 2 - SANS Institute
In this article we finish up our look at PowerShell remoting by examining several options to run PowerShell commands on multiple remote ...
Read more >
Scripts and the Head: What Goes Where? - Gatsby
If the script's type is anything else (e.g. application/ld+json ), it's a data block script. Here's an example: Copycopy code to clipboard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found