From f8b67e12a8ac73fcb1a41aaf51b7cfba37e94e36 Mon Sep 17 00:00:00 2001
From: Mistium <92952823+Mistium@users.noreply.github.com>
Date: Sat, 21 Nov 2026 02:17:05 +0000
Subject: [PATCH 1/2] Draw extension booleans, menus and hidden defaults
correctly in script previews
---
package.json | 2 +-
src/community/commit-changes.js | 2 +-
src/community/components/DiffView.jsx | 3 +-
src/community/scratchblocks-translate.js | 39 ++++++++++++-------
test/unit/community-commit-changes.test.jsx | 1 +
.../community-scratchblocks-translate.test.js | 27 +++++++++++++
6 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/package.json b/package.json
index b6b023c70c4..d9f1d37f231 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "scratch-gui",
- "version": "3.8.0",
+ "version": "3.8.1",
"private": true,
"description": "MistWarp editor, player, and community site",
"author": "MistWarp contributors",
diff --git a/src/community/commit-changes.js b/src/community/commit-changes.js
index 4fac57aeff6..79c351090a4 100644
--- a/src/community/commit-changes.js
+++ b/src/community/commit-changes.js
@@ -51,7 +51,7 @@ export const scriptWasMoved = script => script.change === 'moved';
export const hasMarkedLines = diff => String(diff || '').split('\n').some(line => /^[+-]\s/.test(line));
export const plainScriptTitle = title => String(title || '')
- .replace(/\s*::\s*[a-z]+/gi, '')
+ .replace(/\s*::\s*[#\w-]+/g, '')
.replace(/\[([^\]]*?)(?: v)?\]/g, '$1')
.trim();
diff --git a/src/community/components/DiffView.jsx b/src/community/components/DiffView.jsx
index 708826e7cca..25d73455b28 100644
--- a/src/community/components/DiffView.jsx
+++ b/src/community/components/DiffView.jsx
@@ -10,6 +10,7 @@ import BlocksCompare from './BlocksCompare.jsx';
import EmptyState from './ui/EmptyState.jsx';
import StatusMessage from './ui/StatusMessage.jsx';
import {groupFilesBySprite, spriteLabel, spriteOfPath} from './SpriteList.jsx';
+import {plainScriptTitle} from '../commit-changes.js';
import styles from './DiffView.module.css';
const DIFF_HEADER = /^diff --(?:mwp|git) a\/(.+?) b\/(.+)$/;
@@ -559,7 +560,7 @@ const DiffView = ({diff, spriteFilter = '', onOpenFile = null, loadAsset = null,
>
{blockScripts[group.name].slice(0, MAX_BLOCK_SCRIPTS).map(script => (
- {script.desc}
+ {plainScriptTitle(script.desc)}
))}
diff --git a/src/community/scratchblocks-translate.js b/src/community/scratchblocks-translate.js
index adfbc9615aa..5b80f3dec04 100644
--- a/src/community/scratchblocks-translate.js
+++ b/src/community/scratchblocks-translate.js
@@ -28,7 +28,9 @@ const cleanMenuValue = value => {
const unwrapCall = value => {
let node = value;
- while (node && node.type === 'call' && node.value && node.value !== node) node = node.value;
+ while (node && ((node.type === 'call' && node.value && node.value !== node) || node.type === 'obscured')) {
+ node = node.type === 'obscured' ? (node.active || node.shadow) : node.value;
+ }
return node;
};
@@ -46,9 +48,17 @@ const opcodeOf = node => {
const isMenuCall = node => {
const name = calleeName(node);
- return MENU_SHADOWS.has(name) || name.endsWith('menu') || name.endsWith('menus') || name.startsWith('menu_');
+ return MENU_SHADOWS.has(name) || name.endsWith('menu') || name.endsWith('menus') || name.startsWith('menu_') ||
+ name.includes('_menu_');
};
+const wordsOf = name => String(name)
+ .replace(/_/g, ' ')
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
+ .toLowerCase();
+
+
const translateMenuValue = value => {
if (typeof value === 'string') return cleanMenuValue(value);
const node = unwrapCall(value);
@@ -134,7 +144,11 @@ const inputOf = (node, key, fallback = '0') => {
const booleanInputOf = (node, key) => {
const value = unwrapCall(argValue(node, key));
if (!value || value.type === 'null') return '<>';
- return translateValue(value);
+ const inner = value.type === 'call' && value.callee ? value : null;
+ if (!inner || isMenuCall(inner)) return translateValue(value);
+ // eslint-disable-next-line no-use-before-define
+ const text = translateCall(inner);
+ return text.startsWith('<') && text.endsWith('>') ? text : `<${text}>`;
};
const extensionColor = (text, color) => `${text} :: ${color}`;
@@ -163,7 +177,7 @@ export const translateCall = node => {
const extension = translateKnownExtension(node);
if (extension) return extension;
if (node.callee.type === 'identOrMethod') {
- const name = String(node.callee.method || node.callee.ident || 'extension block').replace(/_/g, ' ');
+ const name = wordsOf(node.callee.method || node.callee.ident || 'extension block');
const inputs = (node.args || [])
.filter(arg => arg.value !== null && typeof arg.value !== 'undefined')
.map(arg => translateValue(arg.value))
@@ -275,8 +289,8 @@ export const translateCall = node => {
case 'operator_lt': return `<${inputOf(node, 'OPERAND1')} < ${inputOf(node, 'OPERAND2')}>`;
case 'operator_equals': return `<${inputOf(node, 'OPERAND1')} = ${inputOf(node, 'OPERAND2')}>`;
case 'operator_gt': return `<${inputOf(node, 'OPERAND1')} > ${inputOf(node, 'OPERAND2')}>`;
- case 'operator_and': return `<${inputOf(node, 'OPERAND1')} and ${inputOf(node, 'OPERAND2')}>`;
- case 'operator_or': return `<${inputOf(node, 'OPERAND1')} or ${inputOf(node, 'OPERAND2')}>`;
+ case 'operator_and': return `<${booleanInputOf(node, 'OPERAND1')} and ${booleanInputOf(node, 'OPERAND2')}>`;
+ case 'operator_or': return `<${booleanInputOf(node, 'OPERAND1')} or ${booleanInputOf(node, 'OPERAND2')}>`;
case 'operator_not': return ``;
case 'operator_join': return `(join ${inputOf(node, 'STRING1', 'apple')} ${inputOf(node, 'STRING2', 'banana')})`;
case 'operator_letter_of': return `(letter ${inputOf(node, 'LETTER', '1')} of ${inputOf(node, 'STRING', 'apple')})`;
@@ -325,14 +339,16 @@ export const translateCall = node => {
case 'pen_setPenHueToNumber': return `set pen color to ${inputOf(node, 'HUE', '50')}`;
case 'pen_changePenHueBy': return `change pen color by ${inputOf(node, 'HUE', '10')}`;
default: {
- const pretty = opcode.includes('_') ? opcode.slice(opcode.indexOf('_') + 1).replace(/_/g, ' ') : opcode;
+ const prefix = opcode.split('_')[0];
+ const core = CORE_OPCODE_PREFIXES.has(prefix);
+ const rest = opcode.includes('_') ? opcode.slice(opcode.indexOf('_') + 1) : opcode;
+ const pretty = core ? rest.replace(/_/g, ' ') : wordsOf(rest);
const inputs = (node.args || [])
.filter(arg => arg.key && arg.value !== null && typeof arg.value !== 'undefined')
.map(arg => translateValue(arg.value))
.join(' ');
const text = inputs ? `${pretty} ${inputs}` : pretty;
- const prefix = opcode.split('_')[0];
- return !CORE_OPCODE_PREFIXES.has(prefix) ? `${text} :: extension` : text;
+ return core ? text : `${text} :: extension`;
}
}
};
@@ -419,10 +435,7 @@ const translateStatements = (calls, indent, marks) => {
};
const conditionOf = (node, key) => {
- const rawValue = argValue(node, key);
- const value = unwrapCall(rawValue);
- if (!value || value.type === 'null') return '<>';
- const text = translateValue(rawValue);
+ const text = booleanInputOf(node, key);
return text.startsWith('<') && text.endsWith('>') ? text : `<${text}>`;
};
diff --git a/test/unit/community-commit-changes.test.jsx b/test/unit/community-commit-changes.test.jsx
index cf73e1a0520..fa209727317 100644
--- a/test/unit/community-commit-changes.test.jsx
+++ b/test/unit/community-commit-changes.test.jsx
@@ -149,6 +149,7 @@ describe('commit changes helpers', () => {
expect(plainScriptTitle('when [any v] key pressed')).toBe('when any key pressed');
expect(plainScriptTitle('isVisible [iframe1] :: extension')).toBe('isVisible iframe1');
expect(plainScriptTitle('Define "Typing system %s"')).toBe('Define "Typing system %s"');
+ expect(plainScriptTitle('set saved (key) to (1) :: #277a59')).toBe('set saved (key) to (1)');
});
test('rounds long decimals in saved values', () => {
diff --git a/test/unit/community-scratchblocks-translate.test.js b/test/unit/community-scratchblocks-translate.test.js
index fe2fb0e0b16..2699b6890de 100644
--- a/test/unit/community-scratchblocks-translate.test.js
+++ b/test/unit/community-scratchblocks-translate.test.js
@@ -35,6 +35,33 @@ const translateSource = source => {
};
describe('scratchblocks translation', () => {
+ test('draws extension booleans, menus and hidden defaults in the right shapes', () => {
+ const parsed = parseFractch([
+ 'sprite "A";',
+ 'when broadcast "X" at 0,0 {',
+ ' if touchingMouse() && lmsLooksPlus.spriteVisible(' +
+ 'TARGET: shadow lmsLooksPlus.menu_spriteMenu(field spriteMenu: "Field to type in")) {',
+ ' append(lists["MOUSE HOVERING"], 0);',
+ ' }',
+ ' if strings.identical(OPERAND1: vars["WHAT WAS TYPED"], OPERAND2: (PASSWORD ?? "a")) {',
+ ' say 1;',
+ ' }',
+ ' if !lmsclonesplus.isClone() {',
+ ' say 2;',
+ ' }',
+ '}',
+ ''
+ ].join('\n'));
+ const text = translateScript(parsed.scripts[0]);
+ expect(text).toContain(
+ 'if < and > then'
+ );
+ expect(text).toContain('if then');
+ expect(text).toContain('if > then');
+ expect(text).not.toContain('<(');
+ expect(text).not.toContain('menu');
+ });
+
test('translates hats to scratch language', () => {
expect(translateSource('when flag {\n}\n')).toContain('when green flag clicked');
expect(translateSource('when broadcast go {\n}\n')).toContain('when I receive [go v]');
From d110a6ae62e5eb47b31fe54e93e6de8c246bf5b7 Mon Sep 17 00:00:00 2001
From: Mistium <92952823+Mistium@users.noreply.github.com>
Date: Sat, 21 Nov 2026 02:19:38 +0000
Subject: [PATCH 2/2] Only treat single-field extension calls named _menu_ as
menus
---
src/community/scratchblocks-translate.js | 11 +++++++----
test/unit/community-scratchblocks-translate.test.js | 11 +++++++++++
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/community/scratchblocks-translate.js b/src/community/scratchblocks-translate.js
index 5b80f3dec04..06eb9a32283 100644
--- a/src/community/scratchblocks-translate.js
+++ b/src/community/scratchblocks-translate.js
@@ -26,10 +26,12 @@ const cleanMenuValue = value => {
return text.replace(/^_+|_+$/g, '');
};
+const obscuredValue = node => (node.active && node.active.type !== 'null' ? node.active : node.shadow);
+
const unwrapCall = value => {
let node = value;
while (node && ((node.type === 'call' && node.value && node.value !== node) || node.type === 'obscured')) {
- node = node.type === 'obscured' ? (node.active || node.shadow) : node.value;
+ node = node.type === 'obscured' ? obscuredValue(node) : node.value;
}
return node;
};
@@ -48,8 +50,10 @@ const opcodeOf = node => {
const isMenuCall = node => {
const name = calleeName(node);
- return MENU_SHADOWS.has(name) || name.endsWith('menu') || name.endsWith('menus') || name.startsWith('menu_') ||
- name.includes('_menu_');
+ if (MENU_SHADOWS.has(name) || name.endsWith('menu') || name.endsWith('menus')) return true;
+ if (name.startsWith('menu_')) return true;
+ const args = node?.args || [];
+ return name.includes('_menu_') && args.length === 1 && args[0].sep === 'field';
};
const wordsOf = name => String(name)
@@ -58,7 +62,6 @@ const wordsOf = name => String(name)
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
.toLowerCase();
-
const translateMenuValue = value => {
if (typeof value === 'string') return cleanMenuValue(value);
const node = unwrapCall(value);
diff --git a/test/unit/community-scratchblocks-translate.test.js b/test/unit/community-scratchblocks-translate.test.js
index 2699b6890de..176e044f10b 100644
--- a/test/unit/community-scratchblocks-translate.test.js
+++ b/test/unit/community-scratchblocks-translate.test.js
@@ -62,6 +62,17 @@ describe('scratchblocks translation', () => {
expect(text).not.toContain('menu');
});
+ test('keeps extension reporters with menu in their name as reporters', () => {
+ const parsed = parseFractch([
+ 'sprite "A";',
+ 'when flag at 0,0 {',
+ ' say lmsFoo.thing_menu_x(VALUE: 3);',
+ '}',
+ ''
+ ].join('\n'));
+ expect(translateScript(parsed.scripts[0])).toContain('say (thing menu x (3) :: extension)');
+ });
+
test('translates hats to scratch language', () => {
expect(translateSource('when flag {\n}\n')).toContain('when green flag clicked');
expect(translateSource('when broadcast go {\n}\n')).toContain('when I receive [go v]');