Skip to content

Commit

Permalink
fix karma bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll committed Jan 31, 2024
1 parent aecb618 commit 28f48a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion newblocks/builtins/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function initFunctions() {
this.setColour(pxt.toolbox.getNamespaceColor('functions'));
this.arguments_ = [];
this.argumentVarModels_ = [];
this.setStartHat(true);
this.hat = "cap";
this.setStatements_(true);
this.statementConnection_ = null;
};
Expand Down
3 changes: 2 additions & 1 deletion newblocks/compiler/typeChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ function mkPlaceholderBlock(e: Environment, parent: Blockly.Block, type?: string
type: "placeholder",
p: mkPoint(type || null),
workspace: e.workspace,
parentBlock_: parent
parentBlock_: parent,
getParent: () => parent
} as any;
}

Expand Down
50 changes: 29 additions & 21 deletions newblocks/fields/field_procedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,48 @@
import * as Blockly from "blockly";

export class FieldProcedure extends Blockly.FieldDropdown {
protected rawValue: string;

constructor(funcname: string, opt_validator?: Blockly.FieldValidator) {
super([["Temp", "Temp"]], opt_validator);
super(createMenuGenerator(), opt_validator);

this.setValue(funcname || '');
}

getOptions() {
return this.generateOptions();
};
getOptions(useCache?: boolean): Blockly.MenuOption[] {
return (this.menuGenerator_ as () => Blockly.MenuOption[])();
}

protected override doClassValidation_(newValue?: string): string {
if (newValue === undefined) {
return null;
}

return newValue;
}

protected override doValueUpdate_(newValue: string): void {
this.rawValue = newValue;
super.doValueUpdate_(newValue);
}

init() {
override init() {
if (this.fieldGroup_) {
// Dropdown has already been initialized once.
return;
}
super.init.call(this);
};

setSourceBlock(block: Blockly.Block) {
(goog as any).asserts.assert(!(block as any).isShadow(),
override setSourceBlock(block: Blockly.Block) {
pxt.Util.assert(!block.isShadow(),
'Procedure fields are not allowed to exist on shadow blocks.');
super.setSourceBlock.call(this, block);
};
}

/**
* Return a sorted list of variable names for procedure dropdown menus.
* Include a special option at the end for creating a new function name.
* @return {!Array.<string>} Array of procedure names.
* @this {pxtblockly.FieldProcedure}
*/
public generateOptions() {
function createMenuGenerator() {
return function (this: FieldProcedure) {
let functionList: string[] = [];
if (this.sourceBlock_ && this.sourceBlock_.workspace) {
let blocks = this.sourceBlock_.workspace.getAllBlocks(false);
Expand Down Expand Up @@ -66,19 +76,17 @@ export class FieldProcedure extends Blockly.FieldDropdown {
functionList.push("Temp");
}

if (this.rawValue && functionList.indexOf(this.rawValue) === -1) {
functionList.push(this.rawValue);
}

// Variables are not language-specific, use the name as both the user-facing
// text and the internal representation.
let options: [string, string][] = [];
for (let i = 0; i < functionList.length; i++) {
options[i] = [functionList[i], functionList[i]];
}
return options;
}

onItemSelected(menu: any, menuItem: any) {
let itemText = menuItem.getValue();
if (itemText !== null) {
this.setValue(itemText);
}
return options;
}
}

0 comments on commit 28f48a1

Please sign in to comment.