Skip to content

Conversation

@LuYifei2011
Copy link

@LuYifei2011 LuYifei2011 commented Sep 19, 2025

Resolves #2336
Closes #7748
Closes #7988

Changes

This pull request adds a new addon: Copy Blocks as Text.
It allows users to copy blocks as scratchblocks text, making it easier to share code in forums or other platforms.

freecompress-._2025-09-19_191744.mp4

Features

  • ⚡ Fast: ~4800 blocks copied in ~14 ms
  • 🧩 Supports all blocks and extensions, including TurboWarp
  • 🌐 Multi-language support (output matches Scratch editor language)
  • 📋 Can copy a single stack or all blocks
  • 🛠 Addresses the issue discussed in New addon: Copy scratchblocks text from editor #7748 (right-clicking reporter/boolean blocks no longer causes errors or blank output)

Reason for changes

This addon enables users to copy scratchblocks text directly, avoiding the need to write it manually.

Tests

Tested on Chrome 140.

I'm new to contributing, so please let me know if anything needs improvement.


Note:

@Samq64
Copy link
Member

Samq64 commented Sep 19, 2025

This is the 3rd open pull request for this feature but they all take different approaches. This one uses the visible text, #7988 uses the block types (e.g. motion_movesteps) and #7748 uses the parse-sb3-blocks library.

@Samq64 Samq64 added new addon Related to new addons to this extension. `scope: addons` should still be added. scope: addon Related to one or multiple addons labels Sep 19, 2025
Copy link
Member

@Samq64 Samq64 left a comment

Choose a reason for hiding this comment

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

Could the non-English translations removed? Translators will handle them later.

return "";
}

if (block.type === "text") {
Copy link
Member

@Samq64 Samq64 Sep 19, 2025

Choose a reason for hiding this comment

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

Colour inputs should also be in square brackets.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry. I'm not entirely sure what your final intention was. The current code seems fine, but happy to revisit if there's more context you'd like to share.

Copy link
Member

Choose a reason for hiding this comment

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

It seems to have always used parentheses which is also fine so I'm not sure why the hex value wasn't surrounded with them before.

@Samq64
Copy link
Member

Samq64 commented Sep 19, 2025

Also custom block uses should have their categroy explicitly set since the definitions might not exist in the copied text.

@Joeclinton1
Copy link
Member

Joeclinton1 commented Sep 19, 2025

The main issue I see with this, which #7748 solves (#7988 does also, but lacks multi language support as a consequence), is how to force English translations so that it can be compatible with the forums, which require English blocks?

this will require either mappings (in which case you should just use #7748), or changing editor language, rerendering, then converting back)

Co-authored-by: Samq64 <81489795+Samq64@users.noreply.github.com>
@WorldLanguages
Copy link
Member

For the record, discussion has moved to #2336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new addon Related to new addons to this extension. `scope: addons` should still be added. scope: addon Related to one or multiple addons

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New editor addon: copy block/stack to clipboard (scratchblocks/BBCode)

4 participants