Skip to content

New addon: editor-copy-scratchblocks#7988

Open
just-a-hriday wants to merge 36 commits intoScratchAddons:masterfrom
just-a-hriday:editor-copy-scratchblocks
Open

New addon: editor-copy-scratchblocks#7988
just-a-hriday wants to merge 36 commits intoScratchAddons:masterfrom
just-a-hriday:editor-copy-scratchblocks

Conversation

@just-a-hriday
Copy link
Contributor

@just-a-hriday just-a-hriday commented Dec 10, 2024

Resolves #2336
Closes #7748
Closes #8572

Changes

Adds an addon that converts blocks in the editor to forums scratchblocks code.
Supports all obsolete blocks and handles all edge cases.

Known issues Comments are not included in the output because scratchblocks only allows you to add comments to outer blocks (so comments on reporters inside other blocks, for example, can't be included), and long comments get cut off.

Scratchblocks doesn't support matrix inputs (the ones used in micro:bit), so they get outputted as dropdowns containing a numerical representation of the matrix.


⬇️

Reason for changes

Makes it much easier to post scripts in the forums.

Tests

Testing with Chrome v131.0.6778.109 on 64 bit Windows.

@Samq64
Copy link
Member

Samq64 commented Dec 11, 2024

This addon has already been submitted in #7748 but I haven't checked the differences in the implementation yet.

@Samq64 Samq64 added status: duplicate Issue or PR already exists type: enhancement New feature for the project new addon Related to new addons to this extension. `scope: addon` should still be added. scope: addon Related to one or multiple addons labels Dec 11, 2024
@just-a-hriday
Copy link
Contributor Author

just-a-hriday commented Dec 11, 2024

This addon has already been submitted in #7748 but I haven't checked the differences in the implementation yet.

Hmm. Mine only supports english, but does give better (and less buggy) output.

Also, there's another implementation that might be possible - just reading the fields in the blocks instead of hardcoding everything. This would give complete language support too.

I tried this a while ago when the forums were still using 2.0 scratchblocks. It didn't work, because a lot of 3.0 blocks have different text from their 2.0 counterparts, and language support was an issue too - but I think it could work with the 3.0 scratchblocks.

@just-a-hriday just-a-hriday marked this pull request as ready for review December 21, 2024 04:38
@just-a-hriday
Copy link
Contributor Author

@WorldLanguages could you review?

@mybearworld
Copy link
Contributor

If this will only support English, it might be a good thing to add a note to the addon explaining that that's intentional (for users of other languages)?

@mybearworld
Copy link
Contributor

When copying from a language other than English, the dropdowns are not translated, leading to a weird mix of languages:

image

@just-a-hriday
Copy link
Contributor Author

When copying from a language other than English, the dropdowns are not translated, leading to a weird mix of languages:

Fixed.

@just-a-hriday
Copy link
Contributor Author

just-a-hriday commented Jan 5, 2025

If this will only support English, it might be a good thing to add a note to the addon explaining that that's intentional (for users of other languages)?

How should it be worded? It needs to be clear that users can use it no matter what their editor language is.

Edit: is this alright?

@just-a-hriday just-a-hriday deleted the editor-copy-scratchblocks branch January 5, 2025 09:05
@just-a-hriday just-a-hriday restored the editor-copy-scratchblocks branch January 5, 2025 09:05
@just-a-hriday just-a-hriday reopened this Jan 5, 2025
@WorldLanguages
Copy link
Member

How should it be worded? It needs to be clear that users can use it no matter what their editor language is.

I don't think it's necessary to clarify that.

Edit: is this alright?

Sure, looks alright to me. Something along the lines of This addon can only output English scratchblocks code. as an info (no need to make it a notice!)

@Samq64 Samq64 removed the status: duplicate Issue or PR already exists label Jan 6, 2025
@pumpkinhasapatch
Copy link
Contributor

pumpkinhasapatch commented Jan 25, 2025

This conflicts with the other editor-copy-scratchblocks addon I'm working on in PR #7748. There is this addon by just-a-hriday, and another version by me with different code but the same basic features and addon ID.

There are advantages of both versions of the addon. My addon uses the parse-sb3-blocks library by apple502j for block conversion, it has a few bugs but support for (almost?) every block and language in the Scratch editor.

On the other hand, hriday's addon accesses blocks more directly and uses less code, but does not support other languages. I think language support is important for non-English Scratchers who write Forum posts, Scratch Wiki pages and other things, though most parts of the Forums only support blocks in English.

It's fine if you want to use this version of the addon instead of mine. I just don't know if I should keep working on this or not.

Co-authored-by: Samq64 <81489795+Samq64@users.noreply.github.com>
@just-a-hriday
Copy link
Contributor Author

@Samq64 How should I add support for turbowarp blocks? Is there a way to check whether the addon is being run in turbowarp? It doesn't make much sense to add hardcoded turbowarp blocks inside the scratch editor too.

@Samq64
Copy link
Member

Samq64 commented Sep 20, 2025

I think mainatining return [], <is compiled>, etc. in Turbowarp's fork of Scratch Addons is fine. If you want to support all of Turbowarp's extensions though then the mapping approach isn't really feasible since there are almost 100 of them now.

@just-a-hriday
Copy link
Contributor Author

The mapping is significantly simpler for turbowarp. With vanilla scratch blocks you have to work around all the inconsistencies and idiosyncrasies of scratchblocks. With the turbowarp blocks you have to override them all to make them render correctly anyways, so it's much simpler. In fact I think it's possible to automate mapping the extension blocks, and I believe that's the best solution here.

For turbowarp blocks Lu Yifei's approach works well too. However it is not reliable for vanilla scratch blocks, so a complicated hybrid approach would have to be used in order to use that method for turbowarp extension blocks and mine for the vanilla blocks. On the other hand there's no need to build mappings for those 100+ extensions if it's done that way.

@Joeclinton1
Copy link
Member

Joeclinton1 commented Sep 20, 2025

If you used the scratch-translations then you'll get most of the mapping for free. But it would require quite a large change to how you're doing things. It is quite a different approach to things.

But you should be able to do most of it dynamically instead of having to hardcode things anymore.

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: addon` should still be added. scope: addon Related to one or multiple addons type: enhancement New feature for the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

8 participants