diff --git a/core/procedures.ts b/core/procedures.ts index 0148b2472f..48342d057e 100644 --- a/core/procedures.ts +++ b/core/procedures.ts @@ -274,7 +274,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): FlyoutItemInfo[] { } /** - * Add items to xmlList for each listed procedure. + * Creates JSON block definitions for each of the given procedures. * * @param procedureList A list of procedures, each of which is defined by a * three-element list of name, parameter list, and return value boolean. diff --git a/core/variables.ts b/core/variables.ts index bde3f763dd..0c04251d01 100644 --- a/core/variables.ts +++ b/core/variables.ts @@ -112,10 +112,29 @@ export function flyoutCategory(workspace: WorkspaceSvg): FlyoutItemInfo[] { ]; } +/** + * Returns the JSON definition for a variable field. + * + * @param variable The variable the field should reference. + * @returns JSON for a variable field. + */ +function generateVariableFieldJson(variable: IVariableModel) { + return { + 'VAR': { + 'name': variable.getName(), + 'type': variable.getType(), + }, + }; +} + /** * Construct the blocks required by the flyout for the variable category. * * @param workspace The workspace containing variables. + * @param variables List of variables to create blocks for. + * @param includeChangeBlocks True to include `change x by _` blocks. + * @param getterType The type of the variable getter block to generate. + * @param setterType The type of the variable setter block to generate. * @returns JSON list of blocks. */ export function flyoutCategoryBlocks( @@ -127,20 +146,10 @@ export function flyoutCategoryBlocks( ): BlockInfo[] { includeChangeBlocks &&= Blocks['math_change']; - const generateVariableFieldJson = ( - variable: IVariableModel, - ) => { - return { - 'VAR': { - 'name': variable.getName(), - 'type': variable.getType(), - }, - }; - }; - const blocks = []; const mostRecentVariable = variables.slice(-1)[0]; if (mostRecentVariable) { + // Show one setter block, with the name of the most recently created variable. if (Blocks[setterType]) { blocks.push({ kind: 'block', @@ -171,6 +180,7 @@ export function flyoutCategoryBlocks( } if (Blocks[getterType]) { + // Show one getter block for each variable, sorted in alphabetical order. blocks.push( ...variables.sort(compareByName).map((variable) => { return {