Refactor Control Blocks: Fix Align Constants, Safe Aliasing, Add Defaults, and Improve Readability #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR modernizes and stabilizes the App Inventor control block definitions (controls_forRange, controls_forEach, and controls_do_then_return). It applies best practices for Blockly block construction, improves developer readability, and ensures consistent runtime behavior across environments.
Key Changes
Alignment Fixes
Replaced deprecated Blockly.inputs.Align.RIGHT with the correct Blockly.ALIGN_RIGHT constant across all block definitions.
Prevents initialization errors in current Blockly builds.
Safe Aliasing
Replaced reference assignment for controls_for alias with a deep clone via Blockly.utils.object.clone().
Ensures that future modifications to controls_forRange do not unintentionally propagate to controls_for.
Improved User Experience
Added default shadow numeric inputs (1 → 10 → 1) for FROM, TO, and BY fields in the forRange block.
Provides a cleaner, more informative default state when users drag the block into the workspace.
Code Modernization
Standardized ES module imports (import * as Blockly from 'blockly/core').
Ensured consistent indentation, naming, and field alignment.
Verified that tooltip and help URL keys remain intact and properly referenced in msg.js.
Comment Preservation
Retained the full historical comment log authored by Lyn and others.
Formatted and aligned historical notes for readability while maintaining attribution.
Structural Consistency
Unified all statement and value input sections for a coherent block layout.
Applied lexicalVariableScopeMixin consistently across loop blocks.
Benefits
Prevents runtime alignment errors in modern Blockly versions.
Improves maintainability and readability of control block source code.
Enhances user experience with sensible defaults.
Keeps full backward compatibility with existing projects.
Testing
Verified blocks load correctly in Blockly Developer Tools and App Inventor environment.
Confirmed that renaming, scoping, and flydown behaviors remain unchanged.
Confirmed tooltips, help URLs, and color styles are applied properly.
Notes
No functional regressions or UI-breaking changes introduced. This is a safe, internal refactor with visible improvements in UX and code quality.